Good advice from Sky. Here are a few more items that may help you.
i have no idea what you mean by local and module scope or global scope variables. < is this where i have 'Dim Currentrow As Long' above all of my code and then again in my code?
Yes. See the bottom of the following link for scope examples: http://www.functionx.com/vbaexcel/Lesson03.htm
I am able locate my field using a comboBox. and then select find and it populated all of my other txtBoxes and cboBoxes but
as soon as i make a change and select update it creates a new row at the bottom of by workbook.
This is probably a clue to the problem, which may be caused by local vs global scope. The row after the last row got assigned to CurrentRow somewhere (probably when you did an Add). My speculation is that you have a local CurrentRow when you loaded the data to be edited. The dim CurrentRow statement in that Sub should probably be deleted. The CurrentRow should have been global with module scope (i.e. Private), defined at the top of the UserForm Module:
It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
This option requires all variables to be declared and will give a compiler error for undeclared variables.
--------------------
Additional debugging tips:
a. Press 'F8' to single step (goes into subroutines and functions).
b. Press SHIFT 'F8' to single step OVER subroutines and functions.
c. Press CTRL 'F8' to stop at the line where the cursor is.
d. 'Left Click' the margin to the left of a line to set (or clear) a BREAKPOINT.
e. Press CTRL 'G' to open the IMMEDIATE WINDOW. 'debug.print' statements send their
output to the IMMEDIATE WINDOW.
f. Select View > Locals to see all variables while debugging.
g. To automatically set a BREAKPOINT at a certain location put in the line:
'Debug.Assert False'
h. To conditionally set a BREAKPOINT at a certain location put in lines similar to:
if i >= 20 and xTV20 > 99.56 then
Debug.Assert False
endif
i. A variable value will be displayed by putting the cursor over the variable name.
Lewis
Bookmarks