View Single Post
  #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)