473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Form Doesn't Go To New Record

I have a form with about 25 fields. In the BeforeUpdate event of the form, I
have code that sets the default value of each field to its current value. For a
new record, I can put the focus in any field to start. If I edit that field and
then click on the new record button in the navigation buttons, the form goes to
a new record and each field has the default value of the previous record. If I
put the focus in any field to start, edit that field go to any other field and
edit it, when I click on the new record button in the navigation buttons the
form does not go to a new record. I have to click the new record button a second
time to go to a new record. I also tried putting the code to set the defaults in
the AfterUpdate event of the form and I get the same problem of having to click
on the new record button twice.

Does anyone have any thoughts as to what may be causing this behaviour?

Thanks!

Steve
Nov 12 '05 #1
15 4633
"Steve" <sp**@nospam.spam> wrote in message
news:gi*****************@newsread3.news.atl.earthl ink.net
I have a form with about 25 fields. In the BeforeUpdate event of the
form, I have code that sets the default value of each field to its
current value. For a new record, I can put the focus in any field to
start. If I edit that field and then click on the new record button
in the navigation buttons, the form goes to a new record and each
field has the default value of the previous record. If I put the
focus in any field to start, edit that field go to any other field
and edit it, when I click on the new record button in the navigation
buttons the form does not go to a new record. I have to click the new
record button a second time to go to a new record. I also tried
putting the code to set the defaults in the AfterUpdate event of the
form and I get the same problem of having to click on the new record
button twice.

Does anyone have any thoughts as to what may be causing this
behaviour?

Thanks!

Steve


I think you'd better post the code behind the form.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
Nov 12 '05 #2
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Ctrl As Control
For Each Ctrl In Me.Controls
If Ctrl.ControlType <> acLabel And Ctrl.ControlType <> acCommandButton Then
If Not IsNull(Ctrl.Value) Then
If InStr(Ctrl.Value, vbCrLf) > 0 Then
MsgBox Ctrl.Controls(0).Caption & " Contains A Line Return." & vbCrLf &
vbCrLf _
& "The New Item Can Not Be Saved In The Database" & vbCrLf _
& "Until The Line Return Is Removed." & vbCrLf & vbCrLf _
& "Please Remove The Line Return!"
Cancel = True
Ctrl.SetFocus
Exit Sub
End If
End If
End If
Next Ctrl

' BeforeUpdate Event Is Used For This So InvNumber = StoreItemID When The Item
Is Saved
Me!InvNumber = Me!StoreItemID
If Me!SetThisItemAsTheDefaultNewItem = True Then
Call SetDefaultValues
Else
Call RemoveDefaultValues
End If
Me!Title.SetFocus
End Sub

Public Sub SetDefaultValues()
On Error GoTo ErrorHandler
Me!Title.DefaultValue = CQuote & Me!Title & CQuote
Me!FeatureFlag.DefaultValue = CQuote & Me!FeatureFlag & CQuote
Me!ShortDesc.DefaultValue = CQuote & Me!ShortDesc & CQuote
Me!Description.DefaultValue = CQuote & Me!Description & CQuote
Me!ThumbImage.DefaultValue = CQuote & Me!ThumbImage & CQuote
Me!FullImage.DefaultValue = CQuote & Me!FullImage & CQuote

If Not IsNull(Me!Category) Then
Me!Category.DefaultValue = CQuote & Me!Category & CQuote
Else
Me!Category.DefaultValue = ""
End If
If Not IsNull(Me!Section) Then
Me!Section.DefaultValue = CQuote & Me!Section & CQuote
Else
Me!Section.DefaultValue = ""
End If
If Not IsNull(Me!Aisle) Then
Me!Aisle.DefaultValue = CQuote & Me!Aisle & CQuote
Else
Me!Aisle.DefaultValue = ""
End If

Me!Alt1.DefaultValue = CQuote & Me!Alt1 & CQuote
Me!Alt2.DefaultValue = CQuote & Me!Alt2 & CQuote
Me!Alt3.DefaultValue = CQuote & Me!Alt3 & CQuote
Me!ListValue.DefaultValue = CQuote & Me!ListValue & CQuote
Me!SalePrice.DefaultValue = CQuote & Me!SalePrice & CQuote
Me!SellingPrice.DefaultValue = CQuote & Me!SellingPrice & CQuote
Me!DatePurchased.DefaultValue = CQuote & Me!DatePurchased & CQuote
Me!ItemCost.DefaultValue = CQuote & Me!ItemCost & CQuote
Me!ShipCost.DefaultValue = CQuote & Me!ShipCost & CQuote

If Not IsNull(Me!InventoryLocation) Then
Me!InventoryLocation.DefaultValue = CQuote & Me!InventoryLocation & CQuote
Else
Me!InventoryLocation.DefaultValue = ""
End If

Me!Inventory.DefaultValue = CQuote & Me!Inventory & CQuote
Me!ReorderPoint.DefaultValue = CQuote & Me!ReorderPoint & CQuote
Me!Quantity.DefaultValue = CQuote & Me!Quantity & CQuote
ExitHere:
Me!Title.SetFocus
Exit Sub
ErrorHandler:
MsgBox Err.Description, , "Error# " & Err.Number
Resume ExitHere
End Sub

Public Sub RemoveDefaultValues()
Me!Title.DefaultValue = ""
Me!FeatureFlag.DefaultValue = ""
Me!ShortDesc.DefaultValue = ""
Me!Description.DefaultValue = ""
Me!ThumbImage.DefaultValue = ""
Me!FullImage.DefaultValue = ""
Me!Category.DefaultValue = ""
Me!Section.DefaultValue = ""
Me!Aisle.DefaultValue = ""
Me!Alt1.DefaultValue = ""
Me!Alt2.DefaultValue = ""
Me!Alt3.DefaultValue = ""
Me!ListValue.DefaultValue = ""
Me!SalePrice.DefaultValue = ""
Me!SellingPrice.DefaultValue = ""
Me!DatePurchased.DefaultValue = ""
Me!ItemCost.DefaultValue = ""
Me!ShipCost.DefaultValue = ""
Me!InventoryLocation.DefaultValue = ""
Me!Inventory.DefaultValue = ""
Me!ReorderPoint.DefaultValue = ""
Me!Quantity.DefaultValue = ""
End Sub

"Dirk Goldgar" <dg@NOdataSPAMgnostics.com> wrote in message
news:Oa**************@TK2MSFTNGP11.phx.gbl...
"Steve" <sp**@nospam.spam> wrote in message
news:gi*****************@newsread3.news.atl.earthl ink.net
I have a form with about 25 fields. In the BeforeUpdate event of the
form, I have code that sets the default value of each field to its
current value. For a new record, I can put the focus in any field to
start. If I edit that field and then click on the new record button
in the navigation buttons, the form goes to a new record and each
field has the default value of the previous record. If I put the
focus in any field to start, edit that field go to any other field
and edit it, when I click on the new record button in the navigation
buttons the form does not go to a new record. I have to click the new
record button a second time to go to a new record. I also tried
putting the code to set the defaults in the AfterUpdate event of the
form and I get the same problem of having to click on the new record
button twice.

Does anyone have any thoughts as to what may be causing this
behaviour?

Thanks!

Steve


I think you'd better post the code behind the form.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Nov 12 '05 #3
"Steve" <sp**@nospam.spam> wrote in message
news:ks*****************@newsread2.news.atl.earthl ink.net
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Ctrl As Control
For Each Ctrl In Me.Controls
If Ctrl.ControlType <> acLabel And Ctrl.ControlType <>
acCommandButton Then If Not IsNull(Ctrl.Value) Then
If InStr(Ctrl.Value, vbCrLf) > 0 Then
MsgBox Ctrl.Controls(0).Caption & " Contains A Line Return."
& vbCrLf & vbCrLf _
& "The New Item Can Not Be Saved In The Database" & vbCrLf _
& "Until The Line Return Is Removed." & vbCrLf & vbCrLf _
& "Please Remove The Line Return!"
Cancel = True
Ctrl.SetFocus
Exit Sub
End If
End If
End If
Next Ctrl

' BeforeUpdate Event Is Used For This So InvNumber = StoreItemID When
The Item Is Saved
Me!InvNumber = Me!StoreItemID
If Me!SetThisItemAsTheDefaultNewItem = True Then
Call SetDefaultValues
Else
Call RemoveDefaultValues
End If
Me!Title.SetFocus
End Sub

Public Sub SetDefaultValues()
On Error GoTo ErrorHandler
Me!Title.DefaultValue = CQuote & Me!Title & CQuote
Me!FeatureFlag.DefaultValue = CQuote & Me!FeatureFlag & CQuote
Me!ShortDesc.DefaultValue = CQuote & Me!ShortDesc & CQuote
Me!Description.DefaultValue = CQuote & Me!Description & CQuote
Me!ThumbImage.DefaultValue = CQuote & Me!ThumbImage & CQuote
Me!FullImage.DefaultValue = CQuote & Me!FullImage & CQuote

If Not IsNull(Me!Category) Then
Me!Category.DefaultValue = CQuote & Me!Category & CQuote
Else
Me!Category.DefaultValue = ""
End If
If Not IsNull(Me!Section) Then
Me!Section.DefaultValue = CQuote & Me!Section & CQuote
Else
Me!Section.DefaultValue = ""
End If
If Not IsNull(Me!Aisle) Then
Me!Aisle.DefaultValue = CQuote & Me!Aisle & CQuote
Else
Me!Aisle.DefaultValue = ""
End If

Me!Alt1.DefaultValue = CQuote & Me!Alt1 & CQuote
Me!Alt2.DefaultValue = CQuote & Me!Alt2 & CQuote
Me!Alt3.DefaultValue = CQuote & Me!Alt3 & CQuote
Me!ListValue.DefaultValue = CQuote & Me!ListValue & CQuote
Me!SalePrice.DefaultValue = CQuote & Me!SalePrice & CQuote
Me!SellingPrice.DefaultValue = CQuote & Me!SellingPrice & CQuote
Me!DatePurchased.DefaultValue = CQuote & Me!DatePurchased & CQuote
Me!ItemCost.DefaultValue = CQuote & Me!ItemCost & CQuote
Me!ShipCost.DefaultValue = CQuote & Me!ShipCost & CQuote

If Not IsNull(Me!InventoryLocation) Then
Me!InventoryLocation.DefaultValue = CQuote & Me!InventoryLocation &
CQuote Else
Me!InventoryLocation.DefaultValue = ""
End If

Me!Inventory.DefaultValue = CQuote & Me!Inventory & CQuote
Me!ReorderPoint.DefaultValue = CQuote & Me!ReorderPoint & CQuote
Me!Quantity.DefaultValue = CQuote & Me!Quantity & CQuote
ExitHere:
Me!Title.SetFocus
Exit Sub
ErrorHandler:
MsgBox Err.Description, , "Error# " & Err.Number
Resume ExitHere
End Sub

Public Sub RemoveDefaultValues()
Me!Title.DefaultValue = ""
Me!FeatureFlag.DefaultValue = ""
Me!ShortDesc.DefaultValue = ""
Me!Description.DefaultValue = ""
Me!ThumbImage.DefaultValue = ""
Me!FullImage.DefaultValue = ""
Me!Category.DefaultValue = ""
Me!Section.DefaultValue = ""
Me!Aisle.DefaultValue = ""
Me!Alt1.DefaultValue = ""
Me!Alt2.DefaultValue = ""
Me!Alt3.DefaultValue = ""
Me!ListValue.DefaultValue = ""
Me!SalePrice.DefaultValue = ""
Me!SellingPrice.DefaultValue = ""
Me!DatePurchased.DefaultValue = ""
Me!ItemCost.DefaultValue = ""
Me!ShipCost.DefaultValue = ""
Me!InventoryLocation.DefaultValue = ""
Me!Inventory.DefaultValue = ""
Me!ReorderPoint.DefaultValue = ""
Me!Quantity.DefaultValue = ""
End Sub

"Dirk Goldgar" <dg@NOdataSPAMgnostics.com> wrote in message
news:Oa**************@TK2MSFTNGP11.phx.gbl...
"Steve" <sp**@nospam.spam> wrote in message
news:gi*****************@newsread3.news.atl.earthl ink.net
I have a form with about 25 fields. In the BeforeUpdate event of the
form, I have code that sets the default value of each field to its
current value. For a new record, I can put the focus in any field to
start. If I edit that field and then click on the new record button
in the navigation buttons, the form goes to a new record and each
field has the default value of the previous record. If I put the
focus in any field to start, edit that field go to any other field
and edit it, when I click on the new record button in the navigation
buttons the form does not go to a new record. I have to click the
new record button a second time to go to a new record. I also tried
putting the code to set the defaults in the AfterUpdate event of the
form and I get the same problem of having to click on the new record
button twice.

Does anyone have any thoughts as to what may be causing this
behaviour?

Thanks!

Steve


I think you'd better post the code behind the form.


I have to say it's not obvious. Let me verify a couple of things.

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?

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?
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.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
Nov 12 '05 #4
"Steve" <sp**@nospam.spam> wrote in message news:<ks*****************@newsread2.news.atl.earth link.net>...
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Ctrl As Control
For Each Ctrl In Me.Controls
If Ctrl.ControlType <> acLabel And Ctrl.ControlType <> acCommandButton Then
If Not IsNull(Ctrl.Value) Then
If InStr(Ctrl.Value, vbCrLf) > 0 Then
MsgBox Ctrl.Controls(0).Caption & " Contains A Line Return." & vbCrLf &
vbCrLf _
& "The New Item Can Not Be Saved In The Database" & vbCrLf _
& "Until The Line Return Is Removed." & vbCrLf & vbCrLf _
& "Please Remove The Line Return!"
Cancel = True
Ctrl.SetFocus
Exit Sub
End If
End If
End If
Next Ctrl

' BeforeUpdate Event Is Used For This So InvNumber = StoreItemID When The Item
Is Saved
Me!InvNumber = Me!StoreItemID
If Me!SetThisItemAsTheDefaultNewItem = True Then
Call SetDefaultValues
Else
Call RemoveDefaultValues
End If
Me!Title.SetFocus
End Sub

Public Sub SetDefaultValues()
On Error GoTo ErrorHandler
Me!Title.DefaultValue = CQuote & Me!Title & CQuote
Me!FeatureFlag.DefaultValue = CQuote & Me!FeatureFlag & CQuote
Me!ShortDesc.DefaultValue = CQuote & Me!ShortDesc & CQuote
Me!Description.DefaultValue = CQuote & Me!Description & CQuote
Me!ThumbImage.DefaultValue = CQuote & Me!ThumbImage & CQuote
Me!FullImage.DefaultValue = CQuote & Me!FullImage & CQuote

If Not IsNull(Me!Category) Then
Me!Category.DefaultValue = CQuote & Me!Category & CQuote
Else
Me!Category.DefaultValue = ""
End If
If Not IsNull(Me!Section) Then
Me!Section.DefaultValue = CQuote & Me!Section & CQuote
Else
Me!Section.DefaultValue = ""
End If
If Not IsNull(Me!Aisle) Then
Me!Aisle.DefaultValue = CQuote & Me!Aisle & CQuote
Else
Me!Aisle.DefaultValue = ""
End If

Me!Alt1.DefaultValue = CQuote & Me!Alt1 & CQuote
Me!Alt2.DefaultValue = CQuote & Me!Alt2 & CQuote
Me!Alt3.DefaultValue = CQuote & Me!Alt3 & CQuote
Me!ListValue.DefaultValue = CQuote & Me!ListValue & CQuote
Me!SalePrice.DefaultValue = CQuote & Me!SalePrice & CQuote
Me!SellingPrice.DefaultValue = CQuote & Me!SellingPrice & CQuote
Me!DatePurchased.DefaultValue = CQuote & Me!DatePurchased & CQuote
Me!ItemCost.DefaultValue = CQuote & Me!ItemCost & CQuote
Me!ShipCost.DefaultValue = CQuote & Me!ShipCost & CQuote

If Not IsNull(Me!InventoryLocation) Then
Me!InventoryLocation.DefaultValue = CQuote & Me!InventoryLocation & CQuote
Else
Me!InventoryLocation.DefaultValue = ""
End If

Me!Inventory.DefaultValue = CQuote & Me!Inventory & CQuote
Me!ReorderPoint.DefaultValue = CQuote & Me!ReorderPoint & CQuote
Me!Quantity.DefaultValue = CQuote & Me!Quantity & CQuote
ExitHere:
Me!Title.SetFocus
Exit Sub
ErrorHandler:
MsgBox Err.Description, , "Error# " & Err.Number
Resume ExitHere
End Sub

Public Sub RemoveDefaultValues()
Me!Title.DefaultValue = ""
Me!FeatureFlag.DefaultValue = ""
Me!ShortDesc.DefaultValue = ""
Me!Description.DefaultValue = ""
Me!ThumbImage.DefaultValue = ""
Me!FullImage.DefaultValue = ""
Me!Category.DefaultValue = ""
Me!Section.DefaultValue = ""
Me!Aisle.DefaultValue = ""
Me!Alt1.DefaultValue = ""
Me!Alt2.DefaultValue = ""
Me!Alt3.DefaultValue = ""
Me!ListValue.DefaultValue = ""
Me!SalePrice.DefaultValue = ""
Me!SellingPrice.DefaultValue = ""
Me!DatePurchased.DefaultValue = ""
Me!ItemCost.DefaultValue = ""
Me!ShipCost.DefaultValue = ""
Me!InventoryLocation.DefaultValue = ""
Me!Inventory.DefaultValue = ""
Me!ReorderPoint.DefaultValue = ""
Me!Quantity.DefaultValue = ""
End Sub


I think I would use a somewhat different approach here. Let the form
save the record. In the AfterUpdate proc of the form, save whatever
key value or values you need to be able to retrieve the record that
you just saved. For example, if your key value is StoreItemID and
that's a long integer, do something like:

dim lngPrevItemID as long ' Do this in the (General) (Declarations)
section of the form so it will be available to all procs in the form

Form_AfterUpdate()

lngPrevItemID = Me.StoreItemID

End Sub

Then in the form's Current event, check to see if you're on a new
record. If so, use the key value you just stored to look up the
previously saved record and load in all the default values. For
example, do something like the following in Form_Current():

Dim rst As Recordset

If Me.NewRecord Then
Set rst = CurrentDB.OpenRecordset("select * from MyTable where
StoreItemID = " & lngPrevItemID
Me!Field1.DefaultValue = rst!Field1
...
Me!Fieldn.DefaultValue = rst!Fieldn
rst.Close
Set rst = Nothing
Else
Me!Field1.DefaultValue = ""
...
Me!Fieldn.DefaultValue = ""
End If

-or-

Dim rst As Recordset

If Me.NewRecord Then
Set rst = Me.RecordSetClone
rst.FindFirst "StoreItemID = " & lngPrevItemID
Me!Field1.DefaultValue = rst!Field1
...
Me!Fieldn.DefaultValue = rst!Fieldn
rst.Close
Set rst = Nothing
Else
Me!Field1.DefaultValue = ""
...
Me!Fieldn.DefaultValue = ""
End If

You might be able to do this with bookmarks as well.

Hope this helps.

Bruce
Nov 12 '05 #5
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. ***

"Dirk Goldgar" <dg@NOdataSPAMgnostics.com> wrote in message
news:eQ**************@TK2MSFTNGP10.phx.gbl... "Steve" <sp**@nospam.spam> wrote in message
news:ks*****************@newsread2.news.atl.earthl ink.net
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Ctrl As Control
For Each Ctrl In Me.Controls
If Ctrl.ControlType <> acLabel And Ctrl.ControlType <>
acCommandButton Then If Not IsNull(Ctrl.Value) Then
If InStr(Ctrl.Value, vbCrLf) > 0 Then
MsgBox Ctrl.Controls(0).Caption & " Contains A Line Return."
& vbCrLf & vbCrLf _
& "The New Item Can Not Be Saved In The Database" & vbCrLf _
& "Until The Line Return Is Removed." & vbCrLf & vbCrLf _
& "Please Remove The Line Return!"
Cancel = True
Ctrl.SetFocus
Exit Sub
End If
End If
End If
Next Ctrl

' BeforeUpdate Event Is Used For This So InvNumber = StoreItemID When
The Item Is Saved
Me!InvNumber = Me!StoreItemID
If Me!SetThisItemAsTheDefaultNewItem = True Then
Call SetDefaultValues
Else
Call RemoveDefaultValues
End If
Me!Title.SetFocus
End Sub

Public Sub SetDefaultValues()
On Error GoTo ErrorHandler
Me!Title.DefaultValue = CQuote & Me!Title & CQuote
Me!FeatureFlag.DefaultValue = CQuote & Me!FeatureFlag & CQuote
Me!ShortDesc.DefaultValue = CQuote & Me!ShortDesc & CQuote
Me!Description.DefaultValue = CQuote & Me!Description & CQuote
Me!ThumbImage.DefaultValue = CQuote & Me!ThumbImage & CQuote
Me!FullImage.DefaultValue = CQuote & Me!FullImage & CQuote

If Not IsNull(Me!Category) Then
Me!Category.DefaultValue = CQuote & Me!Category & CQuote
Else
Me!Category.DefaultValue = ""
End If
If Not IsNull(Me!Section) Then
Me!Section.DefaultValue = CQuote & Me!Section & CQuote
Else
Me!Section.DefaultValue = ""
End If
If Not IsNull(Me!Aisle) Then
Me!Aisle.DefaultValue = CQuote & Me!Aisle & CQuote
Else
Me!Aisle.DefaultValue = ""
End If

Me!Alt1.DefaultValue = CQuote & Me!Alt1 & CQuote
Me!Alt2.DefaultValue = CQuote & Me!Alt2 & CQuote
Me!Alt3.DefaultValue = CQuote & Me!Alt3 & CQuote
Me!ListValue.DefaultValue = CQuote & Me!ListValue & CQuote
Me!SalePrice.DefaultValue = CQuote & Me!SalePrice & CQuote
Me!SellingPrice.DefaultValue = CQuote & Me!SellingPrice & CQuote
Me!DatePurchased.DefaultValue = CQuote & Me!DatePurchased & CQuote
Me!ItemCost.DefaultValue = CQuote & Me!ItemCost & CQuote
Me!ShipCost.DefaultValue = CQuote & Me!ShipCost & CQuote

If Not IsNull(Me!InventoryLocation) Then
Me!InventoryLocation.DefaultValue = CQuote & Me!InventoryLocation &
CQuote Else
Me!InventoryLocation.DefaultValue = ""
End If

Me!Inventory.DefaultValue = CQuote & Me!Inventory & CQuote
Me!ReorderPoint.DefaultValue = CQuote & Me!ReorderPoint & CQuote
Me!Quantity.DefaultValue = CQuote & Me!Quantity & CQuote
ExitHere:
Me!Title.SetFocus
Exit Sub
ErrorHandler:
MsgBox Err.Description, , "Error# " & Err.Number
Resume ExitHere
End Sub

Public Sub RemoveDefaultValues()
Me!Title.DefaultValue = ""
Me!FeatureFlag.DefaultValue = ""
Me!ShortDesc.DefaultValue = ""
Me!Description.DefaultValue = ""
Me!ThumbImage.DefaultValue = ""
Me!FullImage.DefaultValue = ""
Me!Category.DefaultValue = ""
Me!Section.DefaultValue = ""
Me!Aisle.DefaultValue = ""
Me!Alt1.DefaultValue = ""
Me!Alt2.DefaultValue = ""
Me!Alt3.DefaultValue = ""
Me!ListValue.DefaultValue = ""
Me!SalePrice.DefaultValue = ""
Me!SellingPrice.DefaultValue = ""
Me!DatePurchased.DefaultValue = ""
Me!ItemCost.DefaultValue = ""
Me!ShipCost.DefaultValue = ""
Me!InventoryLocation.DefaultValue = ""
Me!Inventory.DefaultValue = ""
Me!ReorderPoint.DefaultValue = ""
Me!Quantity.DefaultValue = ""
End Sub

"Dirk Goldgar" <dg@NOdataSPAMgnostics.com> wrote in message
news:Oa**************@TK2MSFTNGP11.phx.gbl...
"Steve" <sp**@nospam.spam> wrote in message
news:gi*****************@newsread3.news.atl.earthl ink.net
I have a form with about 25 fields. In the BeforeUpdate event of the
form, I have code that sets the default value of each field to its
current value. For a new record, I can put the focus in any field to
start. If I edit that field and then click on the new record button
in the navigation buttons, the form goes to a new record and each
field has the default value of the previous record. If I put the
focus in any field to start, edit that field go to any other field
and edit it, when I click on the new record button in the navigation
buttons the form does not go to a new record. I have to click the
new record button a second time to go to a new record. I also tried
putting the code to set the defaults in the AfterUpdate event of the
form and I get the same problem of having to click on the new record
button twice.

Does anyone have any thoughts as to what may be causing this
behaviour?

Thanks!

Steve

I think you'd better post the code behind the form.


I have to say it's not obvious. Let me verify a couple of things.

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?

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?
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.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Nov 12 '05 #6
rkc

"Bruce" <br***@aristotle.net> wrote in message
news:d3**************************@posting.google.c om...
I think I would use a somewhat different approach here. Let the form
save the record. In the AfterUpdate proc of the form, save whatever
key value or values you need to be able to retrieve the record that
you just saved. For example, if your key value is StoreItemID and
that's a long integer, do something like:

dim lngPrevItemID as long ' Do this in the (General) (Declarations)
section of the form so it will be available to all procs in the form

Form_AfterUpdate()

lngPrevItemID = Me.StoreItemID

End Sub

Then in the form's Current event, check to see if you're on a new
record. If so, use the key value you just stored to look up the
previously saved record and load in all the default values. For
example, do something like the following in Form_Current():

Dim rst As Recordset

If Me.NewRecord Then
Set rst = CurrentDB.OpenRecordset("select * from MyTable where
StoreItemID = " & lngPrevItemID
Me!Field1.DefaultValue = rst!Field1
...
Me!Fieldn.DefaultValue = rst!Fieldn
rst.Close
Set rst = Nothing
Else
Me!Field1.DefaultValue = ""
...
Me!Fieldn.DefaultValue = ""
End If

-or-

Dim rst As Recordset

If Me.NewRecord Then
Set rst = Me.RecordSetClone
rst.FindFirst "StoreItemID = " & lngPrevItemID
Me!Field1.DefaultValue = rst!Field1
...
Me!Fieldn.DefaultValue = rst!Fieldn
rst.Close
Set rst = Nothing
Else
Me!Field1.DefaultValue = ""
...
Me!Fieldn.DefaultValue = ""
End If


My first thought would be to write a class that extends a textbox to
include the behaviour that is wanted. You could handle both the
setting of a defaultvalue and the removal of CRLF's.

Something like:

<class>
Option Compare Database
Option Explicit

Private WithEvents frm As Access.Form
Private txtbox As Access.TextBox

Public Sub Init(tb As Access.TextBox)
Set frm = tb.parent
Set txtbox = tb
frm.BeforeUpdate = "[Event Procedure]"
End Sub

Private Sub frm_BeforeUpdate(Cancel As Integer)
If Len(txtbox.Value & vbNullString) > 0 Then
txtbox.Value = Replace(txtbox.Value, vbCrLf, " ")
txtbox.DefaultValue = Chr$(34) & txtbox.Value & Chr$(34)
End If
End Sub

Private Sub Class_Terminate()
If Not txtbox Is Nothing Then Set txtbox = Nothing
If Not frm Is Nothing Then Set frm = Nothing
End Sub
</class>

Set and load all the textboxes you want to have the behaviour
into a collection in the form's open event.
Nov 12 '05 #7
RKC,

Thanks for responding!

To try and learn something new and understand what you propose, I have some
questions:
1. What is the advantage to what you propose?

2. Where specifically does your code go?

3. <<Set and load all the textboxes you want to have the behaviour into a
collection in the form's open event.>> How do you do this? There around 25
fields on the form, would you then cycle through the collection in the
BeforeUpdate event code?

4. There are a couple of memo fields, how are they handled?

5. << txtbox.Value = Replace(txtbox.Value, vbCrLf, " ")>> Why are you replacing
a CrLf with a space rather than a null string?

6. What causes Private Sub Class_Terminate() to execute?

Thank you very much for your help!

Steve

"rkc" <rk*@yabba.dabba.do.rochester.rr.bomb> wrote in message
news:jR******************@twister.nyroc.rr.com...

"Bruce" <br***@aristotle.net> wrote in message
news:d3**************************@posting.google.c om...
I think I would use a somewhat different approach here. Let the form
save the record. In the AfterUpdate proc of the form, save whatever
key value or values you need to be able to retrieve the record that
you just saved. For example, if your key value is StoreItemID and
that's a long integer, do something like:

dim lngPrevItemID as long ' Do this in the (General) (Declarations)
section of the form so it will be available to all procs in the form

Form_AfterUpdate()

lngPrevItemID = Me.StoreItemID

End Sub

Then in the form's Current event, check to see if you're on a new
record. If so, use the key value you just stored to look up the
previously saved record and load in all the default values. For
example, do something like the following in Form_Current():

Dim rst As Recordset

If Me.NewRecord Then
Set rst = CurrentDB.OpenRecordset("select * from MyTable where
StoreItemID = " & lngPrevItemID
Me!Field1.DefaultValue = rst!Field1
...
Me!Fieldn.DefaultValue = rst!Fieldn
rst.Close
Set rst = Nothing
Else
Me!Field1.DefaultValue = ""
...
Me!Fieldn.DefaultValue = ""
End If

-or-

Dim rst As Recordset

If Me.NewRecord Then
Set rst = Me.RecordSetClone
rst.FindFirst "StoreItemID = " & lngPrevItemID
Me!Field1.DefaultValue = rst!Field1
...
Me!Fieldn.DefaultValue = rst!Fieldn
rst.Close
Set rst = Nothing
Else
Me!Field1.DefaultValue = ""
...
Me!Fieldn.DefaultValue = ""
End If


My first thought would be to write a class that extends a textbox to
include the behaviour that is wanted. You could handle both the
setting of a defaultvalue and the removal of CRLF's.

Something like:

<class>
Option Compare Database
Option Explicit

Private WithEvents frm As Access.Form
Private txtbox As Access.TextBox

Public Sub Init(tb As Access.TextBox)
Set frm = tb.parent
Set txtbox = tb
frm.BeforeUpdate = "[Event Procedure]"
End Sub

Private Sub frm_BeforeUpdate(Cancel As Integer)
If Len(txtbox.Value & vbNullString) > 0 Then
txtbox.Value = Replace(txtbox.Value, vbCrLf, " ")
txtbox.DefaultValue = Chr$(34) & txtbox.Value & Chr$(34)
End If
End Sub

Private Sub Class_Terminate()
If Not txtbox Is Nothing Then Set txtbox = Nothing
If Not frm Is Nothing Then Set frm = Nothing
End Sub
</class>

Set and load all the textboxes you want to have the behaviour
into a collection in the form's open event.

Nov 12 '05 #8
rkc

"Steve" <sp**@nospam.spam> wrote in message
news:2y*****************@newsread2.news.atl.earthl ink.net...

To try and learn something new and understand what you propose, I have some questions:
1. What is the advantage to what you propose?
The code for the textbox(s) behaviour is all in one place, in a
class module.
2. Where specifically does your code go?
The code between <class> and </class> goes in a new class module.
3. <<Set and load all the textboxes you want to have the behaviour into a collection in the form's open event.>> How do you do this? There around 25 fields on the form, would you then cycle through the collection in the
BeforeUpdate event code?

4. There are a couple of memo fields, how are they handled?
Same as text fields

5. << txtbox.Value = Replace(txtbox.Value, vbCrLf, " ")>> Why are you replacing a CrLf with a space rather than a null string?
Because you can end up with two words run together if you don't.
6. What causes Private Sub Class_Terminate() to execute?


The object you create from the class definition goes out of scope.
Actually all objects created in the class should be destroyed when
the class goes out of scope any way. Destroying them explicity is
just a habit.
I posted a sample .mdb at the following url. Let me know when/if you
download it so I can take it off line.

"http://www8.brinkster.com/rkc/pcDataSheet.mdb


Nov 12 '05 #9
I just downloaded the sample mdb! I really appreciate you doing that for me.

<<The code between <class> and </class> goes in a new class module.>> By new
class module, do you mean a standard module?

Thanks for all the help you have given!

Steve

"rkc" <rk*@yabba.dabba.do.rochester.rr.bomb> wrote in message
news:hM******************@twister.nyroc.rr.com...

"Steve" <sp**@nospam.spam> wrote in message
news:2y*****************@newsread2.news.atl.earthl ink.net...

To try and learn something new and understand what you propose, I have

some
questions:
1. What is the advantage to what you propose?


The code for the textbox(s) behaviour is all in one place, in a
class module.
2. Where specifically does your code go?


The code between <class> and </class> goes in a new class module.
> 3. <<Set and load all the textboxes you want to have the behaviour into

a
collection in the form's open event.>> How do you do this? There around

25
fields on the form, would you then cycle through the collection in the
BeforeUpdate event code?

4. There are a couple of memo fields, how are they handled?


Same as text fields

5. << txtbox.Value = Replace(txtbox.Value, vbCrLf, " ")>> Why are you

replacing
a CrLf with a space rather than a null string?


Because you can end up with two words run together if you don't.
6. What causes Private Sub Class_Terminate() to execute?


The object you create from the class definition goes out of scope.
Actually all objects created in the class should be destroyed when
the class goes out of scope any way. Destroying them explicity is
just a habit.
I posted a sample .mdb at the following url. Let me know when/if you
download it so I can take it off line.

"http://www8.brinkster.com/rkc/pcDataSheet.mdb


Nov 12 '05 #10
Tried your class out and works great!

I'm working on fully understanding it now :).

What is the difference between a module and a class?

Appreciate all your help.

Steve
"rkc" <rk*@yabba.dabba.do.rochester.rr.bomb> wrote in message
news:hM******************@twister.nyroc.rr.com...

"Steve" <sp**@nospam.spam> wrote in message
news:2y*****************@newsread2.news.atl.earthl ink.net...

To try and learn something new and understand what you propose, I have

some
questions:
1. What is the advantage to what you propose?


The code for the textbox(s) behaviour is all in one place, in a
class module.
2. Where specifically does your code go?


The code between <class> and </class> goes in a new class module.
> 3. <<Set and load all the textboxes you want to have the behaviour into

a
collection in the form's open event.>> How do you do this? There around

25
fields on the form, would you then cycle through the collection in the
BeforeUpdate event code?

4. There are a couple of memo fields, how are they handled?


Same as text fields

5. << txtbox.Value = Replace(txtbox.Value, vbCrLf, " ")>> Why are you

replacing
a CrLf with a space rather than a null string?


Because you can end up with two words run together if you don't.
6. What causes Private Sub Class_Terminate() to execute?


The object you create from the class definition goes out of scope.
Actually all objects created in the class should be destroyed when
the class goes out of scope any way. Destroying them explicity is
just a habit.
I posted a sample .mdb at the following url. Let me know when/if you
download it so I can take it off line.

"http://www8.brinkster.com/rkc/pcDataSheet.mdb


Nov 12 '05 #11
rkc

"Steve" <sp**@nospam.spam> wrote in message
news:F2*****************@newsread2.news.atl.earthl ink.net...
Tried your class out and works great!

I'm working on fully understanding it now :).

What is the difference between a module and a class?


A class defines a creatable object. When you use Access you
are using objects all the time. Recordsets, Fields, Controls
are all objects defined in the DAO library. Using a Class
module you get to define your own objects which you can
then create and use in the same way.

Nov 12 '05 #12
Bruce,

I tried your suggestion and experienced the same behaviour described under my
reply to Dirk.

Steve
"Bruce" <br***@aristotle.net> wrote in message
news:d3**************************@posting.google.c om...
"Steve" <sp**@nospam.spam> wrote in message

news:<ks*****************@newsread2.news.atl.earth link.net>...
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Ctrl As Control
For Each Ctrl In Me.Controls
If Ctrl.ControlType <> acLabel And Ctrl.ControlType <> acCommandButton Then If Not IsNull(Ctrl.Value) Then
If InStr(Ctrl.Value, vbCrLf) > 0 Then
MsgBox Ctrl.Controls(0).Caption & " Contains A Line Return." & vbCrLf & vbCrLf _
& "The New Item Can Not Be Saved In The Database" & vbCrLf _
& "Until The Line Return Is Removed." & vbCrLf & vbCrLf _
& "Please Remove The Line Return!"
Cancel = True
Ctrl.SetFocus
Exit Sub
End If
End If
End If
Next Ctrl

' BeforeUpdate Event Is Used For This So InvNumber = StoreItemID When The Item Is Saved
Me!InvNumber = Me!StoreItemID
If Me!SetThisItemAsTheDefaultNewItem = True Then
Call SetDefaultValues
Else
Call RemoveDefaultValues
End If
Me!Title.SetFocus
End Sub

Public Sub SetDefaultValues()
On Error GoTo ErrorHandler
Me!Title.DefaultValue = CQuote & Me!Title & CQuote
Me!FeatureFlag.DefaultValue = CQuote & Me!FeatureFlag & CQuote
Me!ShortDesc.DefaultValue = CQuote & Me!ShortDesc & CQuote
Me!Description.DefaultValue = CQuote & Me!Description & CQuote
Me!ThumbImage.DefaultValue = CQuote & Me!ThumbImage & CQuote
Me!FullImage.DefaultValue = CQuote & Me!FullImage & CQuote

If Not IsNull(Me!Category) Then
Me!Category.DefaultValue = CQuote & Me!Category & CQuote
Else
Me!Category.DefaultValue = ""
End If
If Not IsNull(Me!Section) Then
Me!Section.DefaultValue = CQuote & Me!Section & CQuote
Else
Me!Section.DefaultValue = ""
End If
If Not IsNull(Me!Aisle) Then
Me!Aisle.DefaultValue = CQuote & Me!Aisle & CQuote
Else
Me!Aisle.DefaultValue = ""
End If

Me!Alt1.DefaultValue = CQuote & Me!Alt1 & CQuote
Me!Alt2.DefaultValue = CQuote & Me!Alt2 & CQuote
Me!Alt3.DefaultValue = CQuote & Me!Alt3 & CQuote
Me!ListValue.DefaultValue = CQuote & Me!ListValue & CQuote
Me!SalePrice.DefaultValue = CQuote & Me!SalePrice & CQuote
Me!SellingPrice.DefaultValue = CQuote & Me!SellingPrice & CQuote
Me!DatePurchased.DefaultValue = CQuote & Me!DatePurchased & CQuote
Me!ItemCost.DefaultValue = CQuote & Me!ItemCost & CQuote
Me!ShipCost.DefaultValue = CQuote & Me!ShipCost & CQuote

If Not IsNull(Me!InventoryLocation) Then
Me!InventoryLocation.DefaultValue = CQuote & Me!InventoryLocation & CQuote
Else
Me!InventoryLocation.DefaultValue = ""
End If

Me!Inventory.DefaultValue = CQuote & Me!Inventory & CQuote
Me!ReorderPoint.DefaultValue = CQuote & Me!ReorderPoint & CQuote
Me!Quantity.DefaultValue = CQuote & Me!Quantity & CQuote
ExitHere:
Me!Title.SetFocus
Exit Sub
ErrorHandler:
MsgBox Err.Description, , "Error# " & Err.Number
Resume ExitHere
End Sub

Public Sub RemoveDefaultValues()
Me!Title.DefaultValue = ""
Me!FeatureFlag.DefaultValue = ""
Me!ShortDesc.DefaultValue = ""
Me!Description.DefaultValue = ""
Me!ThumbImage.DefaultValue = ""
Me!FullImage.DefaultValue = ""
Me!Category.DefaultValue = ""
Me!Section.DefaultValue = ""
Me!Aisle.DefaultValue = ""
Me!Alt1.DefaultValue = ""
Me!Alt2.DefaultValue = ""
Me!Alt3.DefaultValue = ""
Me!ListValue.DefaultValue = ""
Me!SalePrice.DefaultValue = ""
Me!SellingPrice.DefaultValue = ""
Me!DatePurchased.DefaultValue = ""
Me!ItemCost.DefaultValue = ""
Me!ShipCost.DefaultValue = ""
Me!InventoryLocation.DefaultValue = ""
Me!Inventory.DefaultValue = ""
Me!ReorderPoint.DefaultValue = ""
Me!Quantity.DefaultValue = ""
End Sub


I think I would use a somewhat different approach here. Let the form
save the record. In the AfterUpdate proc of the form, save whatever
key value or values you need to be able to retrieve the record that
you just saved. For example, if your key value is StoreItemID and
that's a long integer, do something like:

dim lngPrevItemID as long ' Do this in the (General) (Declarations)
section of the form so it will be available to all procs in the form

Form_AfterUpdate()

lngPrevItemID = Me.StoreItemID

End Sub

Then in the form's Current event, check to see if you're on a new
record. If so, use the key value you just stored to look up the
previously saved record and load in all the default values. For
example, do something like the following in Form_Current():

Dim rst As Recordset

If Me.NewRecord Then
Set rst = CurrentDB.OpenRecordset("select * from MyTable where
StoreItemID = " & lngPrevItemID
Me!Field1.DefaultValue = rst!Field1
...
Me!Fieldn.DefaultValue = rst!Fieldn
rst.Close
Set rst = Nothing
Else
Me!Field1.DefaultValue = ""
...
Me!Fieldn.DefaultValue = ""
End If

-or-

Dim rst As Recordset

If Me.NewRecord Then
Set rst = Me.RecordSetClone
rst.FindFirst "StoreItemID = " & lngPrevItemID
Me!Field1.DefaultValue = rst!Field1
...
Me!Fieldn.DefaultValue = rst!Fieldn
rst.Close
Set rst = Nothing
Else
Me!Field1.DefaultValue = ""
...
Me!Fieldn.DefaultValue = ""
End If

You might be able to do this with bookmarks as well.

Hope this helps.

Bruce

Nov 12 '05 #13
I previously tried Bruce's suggestion and experienced the same behaviour as
described in my reply to Dirk. Before I try the Class route, is it different
from what Bruce suggested? I note that the Class uses the form's BeforeUpdate
event in the same way to set the default values.

Steve
"rkc" <rk*@yabba.dabba.do.rochester.rr.bomb> wrote in message
news:J7*******************@twister.nyroc.rr.com...

"Steve" <sp**@nospam.spam> wrote in message
news:F2*****************@newsread2.news.atl.earthl ink.net...
Tried your class out and works great!

I'm working on fully understanding it now :).

What is the difference between a module and a class?


A class defines a creatable object. When you use Access you
are using objects all the time. Recordsets, Fields, Controls
are all objects defined in the DAO library. Using a Class
module you get to define your own objects which you can
then create and use in the same way.

Nov 12 '05 #14
rkc

"Steve" <sp**@nospam.spam> wrote in message
news:uN*****************@newsread2.news.atl.earthl ink.net...
I previously tried Bruce's suggestion and experienced the same behaviour as described in my reply to Dirk. Before I try the Class route, is it different from what Bruce suggested? I note that the Class uses the form's BeforeUpdate event in the same way to set the default values.

The class method is just a modified way of doing the same thing you were
doing in the first place. Bruce is using a query to retrieve all the fields
from
the previously entered record.

If you use the form in the sample .mdb you downloaded to enter new records
you'll see that it does not exibit the same behaviour as you described. As
far
as why that is... I really don't have a clue.
Nov 12 '05 #15
First, thanks to everyone who responded!

I found what was causing the problem but don't know why! I experienced the same
behaviour when I tried Bruce's suggestion. The one difference was that my code
was in the BeforeUpdate event rather than the AfterUpdate event. Bruce's
suggestion put the code that set the Default Values of all the fields in the
OnCurrent event. So while experimenting, I turned off the Oncurrent code so only
the BeforeUpdate code would run. Then after making some entries in the form, I
clicked on the new record button and was surprised that the form did not go to a
new record. I still had to click twice. This meant that the problem was in the
BeforeUpdate code. The first thing I tried was to comment out the line of code
setting focus on the Title control at the end of the code. (Title is the first
field in the tab order) After I did this, everything surprisingly worked as
expected taking only one click to go to a new record. After discovering this, I
went back and tried setting focus on other fields in the form and no matter
which field I picked, I experienced the same problem behaviour. So the SetFocus
line of code was removed. I then activated the OnCurrent code and everything
continued to work as expected!! I added a line of code in the OnCurrent event to
setfocus on Title and everything continued to work as expected!! So problem
solved - but don't know why setting focus to a field on the form in the
BeforeUpdate event made it necessary to click the new record button twice to
move the form to a new record. I tried setting the cycle property to All Records
and Current Record and the problem persisted at both settings.

Thanks again to everyone!

Steve

"Steve" <sp**@nospam.spam> wrote in message
news:gi*****************@newsread3.news.atl.earthl ink.net...
I have a form with about 25 fields. In the BeforeUpdate event of the form, I
have code that sets the default value of each field to its current value. For a new record, I can put the focus in any field to start. If I edit that field and then click on the new record button in the navigation buttons, the form goes to a new record and each field has the default value of the previous record. If I put the focus in any field to start, edit that field go to any other field and
edit it, when I click on the new record button in the navigation buttons the
form does not go to a new record. I have to click the new record button a second time to go to a new record. I also tried putting the code to set the defaults in the AfterUpdate event of the form and I get the same problem of having to click on the new record button twice.

Does anyone have any thoughts as to what may be causing this behaviour?

Thanks!

Steve

Nov 12 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Randell D. | last post by:
Folks, I am working on a contact db using PHP and MySQL. My results so far outputs a slimed down version of records to the browser. I would like to implement a method whereby the user can...
4
by: amywolfie | last post by:
I've been trying to do something for about 3 days – I get close, but not 100%. I am trying to: Open frmRevisionHistory from a button on frmFeeInput. If there is NO RELATED RECORD, then I...
1
by: Ian | last post by:
I want to open a form at a particular record, but I think I'm running into problems because the recordsource query is executing asynchronously. In the form's open event I use...
18
by: Darryl Kerkeslager | last post by:
I don't do much with subforms - in fact I've deliberately avoided them - but .... I have a tab control that will contain several subforms, each bound to a separate table, and each table/subform...
4
by: Pierre | last post by:
Hi all, To ease load on a network i close automatically form open with a timer reset by user actions. If the time is expired i go through the collections of form and table and close all those...
22
by: Br | last post by:
First issue: When using ADPs you no longer have the ability to issue a me.refresh to save the current record on a form (the me.refresh does a requery in an ADP). We usually do this before...
5
by: ortaias | last post by:
I have a form which calls up a second form for purposes of data entry. When closing the data entry form and returning to the main form, things don't work as expected. When I return to the main...
4
by: Macbane | last post by:
Hi, I have a 'main' form called frmIssues which has a subform control (named linkIssuesDrug) containing the subform sfrmLink_Issues_Drugs. A control button on the main form opens a pop-up form...
5
by: Neil | last post by:
"lyle" <lyle.fairfield@gmail.comwrote in message news:48c3dde7-07bd-48b8-91c3-e157b703f92b@f3g2000hsg.googlegroups.com... Question for you. I'm doing something similar, only, instead of opening...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.