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