A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Form Doesn't Go To New Record



 
 
Thread Tools Display Modes
  #1  
Old May 14th, 2004, 02:29 AM
Steve
external usenet poster
 
Posts: n/a
Default 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


  #2  
Old May 14th, 2004, 02:58 AM
Dirk Goldgar
external usenet poster
 
Posts: n/a
Default Form Doesn't Go To New Record

"Steve" wrote in message
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)


  #3  
Old May 14th, 2004, 02:03 PM
Steve
external usenet poster
 
Posts: n/a
Default Form Doesn't Go To New Record

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


ExitHe
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" wrote in message
...
"Steve" wrote in message
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)




  #4  
Old May 14th, 2004, 06:22 PM
Dirk Goldgar
external usenet poster
 
Posts: n/a
Default Form Doesn't Go To New Record

"Steve" wrote in message
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


ExitHe
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" wrote in message
...
"Steve" wrote in message
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)


  #5  
Old May 14th, 2004, 08:36 PM
Bruce
external usenet poster
 
Posts: n/a
Default Form Doesn't Go To New Record

"Steve" wrote in message 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


ExitHe
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
  #6  
Old May 15th, 2004, 01:43 AM
PC Datasheet
external usenet poster
 
Posts: n/a
Default Form Doesn't Go To New Record

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" wrote in message
...
"Steve" wrote in message
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


ExitHe
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" wrote in message
...
"Steve" wrote in message
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)





  #7  
Old May 15th, 2004, 05:17 AM
rkc
external usenet poster
 
Posts: n/a
Default Form Doesn't Go To New Record


"Bruce" wrote in message
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.


  #8  
Old May 15th, 2004, 03:11 PM
Steve
external usenet poster
 
Posts: n/a
Default Form Doesn't Go To New Record

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" wrote in message
...

"Bruce" wrote in message
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.




  #9  
Old May 15th, 2004, 05:42 PM
rkc
external usenet poster
 
Posts: n/a
Default Form Doesn't Go To New Record


"Steve" wrote in message
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






  #10  
Old May 15th, 2004, 08:11 PM
Steve
external usenet poster
 
Posts: n/a
Default Form Doesn't Go To New Record

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" wrote in message
...

"Steve" wrote in message
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








 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:32 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.