Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 OnCurrent event procedures on same form 1

Status
Not open for further replies.

houstonbill

Technical User
Nov 6, 2006
92
Have a form that opens with an on current event as follows in order to populate users ID:

Private Sub Form_Current()
Me.BadgeID = DLookup("BadgeId", "qry_User")
Me.Firstname = DLookup("Firstname", "qry_User")
Me.Lastname = DLookup("Lastname", "qry_User")
Me.cc_number = DLookup("cc_number", "qry_User")

End Sub

The form also has an ID # (auto number)which currently populates each time the form is opened. Even if it is closed with no entries, the ID # shows up as a record with no entires. Therefore I want to do another "On Current Event" like follows but I can't seem to figure out how to align it. Or should I use a differnt event? Help would be appreciated.

If Me.NewRecord Then
On Error Resume Next 'It should never occur, just to be sure...
Me!ID.DefaultValue = NZ(DMax("[SuggestionID]", "frm_Suggestions"), 0) + 1
End If


 
Hi, houstonbill,

You could place your NewRecord code in the form's Current event, as you suggest... but this forces the code to populate your ID field, and barring some other validation routine, will be saved when you exit the record/form, whether any other fields are entered or not. Seems this is precisely what you are trying to avoid.

So... go ahead and use your code in the form's Current event, but validate the data in the form's BeforeUpdate event, so you can use the event's Cancel argument and the Undo method to prevent blank (except for ID) records from being saved.

HTH,

Ken S.
 
That does exactly what I want. Thanks for helping me to reorganize just a bit. I was having a bit of a mental block.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top