Dirk,
Thanks for the follow-up!!
Is the "new record" button you're clicking one of the standard
navigation buttons provided by having the form's NavigationButtons
property set to Yes?
*** Yes, the button with the astrisk at the far right. ***
As I interpret your description of the problem, you are contrasting two
behaviors, identified as A and B below:
(A) Open Form. Go to new record. Edit the data in a control. Click
"new record" button. Form goes to a new record.
(B) Open Form. Go to new record. Edit the data in a control. Edit the
data in another control. Click "new record" button. Form does *not* go
to a new record, but stays on the current record. If you click the
button again, *then* the form goes to a new record.
Do the above statements correctly decribe what you are doing and seeing?
*** SetThisItemAsTheDefaultNewItem is an option button on the form and is
refeered to in the BeforeUpdate code. True calls the Public Sub
SetDefaultValues() and False calls the Public Sub RemoveDefaultValues(). I get
the same behaviour whether the option button is set to True or False. The
behaviour occurs on the first record as well as all subsequent records. When the
form opens focus is on the first field in the tab order (Title). If I make an
entry in that field and click on the New Record button, the form goes to a new
record. If I tab or use the mouse to move the cursor to any other field and make
an entry only in that field and then click the New Record button, the cursor
jumps to the first field in the tab order but the form does not go to a new
record. I have to click the New Record button again. The same thing happens on
all subsequent new records.
Note that at the end of the Public Sub SetDefaultValues() code, focus is set for
the field 'Title'. If I change the code to set focus on another field, I get the
same behaviour. If I edit only the field that got the focus, one click goes to a
new record. But if I tab or use the mouse to go to any other field, it takes two
clicks to go to a new record. Public Sub RemoveDefaultValues() as is does not
set the focus after running so focus goes to the first field in the tab order.
And again I get the same behaviour. If I change the tab order, I get the same
behaviour. I tried adding code in the Public Sub RemoveDefaultValues() to set
focus to a particular field and get the same behaviour. ***
Please verify exactly what it takes to get the dfferent behaviors,
starting with a fresh opening of the form each time. Are you sure it
doesn't matter what controls you edit?
I notice that your code that loops through the controls excludes only
labels and command buttons. There could conceivably be other types of
controls that don't have a Value property -- lines, boxes, and such.
Are you sure you don't have a problem there? You don't have error
trapping turned off, do you? You have no error-handling in the
Form_BeforeUpdate procedure.
*** The purpose of the code at the beginning is to look for line returns in the
data entry fields. The data entered on the form is saved to the database and
also exported to a MySQL webstore. The webstore can not correctly process the
data if it contains line returns when it imports the data. In regards to
error-handling, I have not raised any errors in the various ways I have tried to
make this work.
The database and the webstore interface have worked flawlessly for several
months. The form being discussed is for adding new items to the database and to
the webstore. Sometimes a series of new items is added where most of the fields
are the same for each item. Rather than typing in the same information for each
item, I'm trying to set up a way to duplicate the previous item and then edit
the few fields that need changed. I'm trying to do it through the default value
of all the fields to avoid creating duplicate item records. ***