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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which event trigger should I use?

Status
Not open for further replies.

benderulz

IS-IT--Management
Nov 2, 2010
43
US
I have a form that or may not contain multiple records. I want to check the record count and display a message to the user if multiples exist. I put the code below in the "On Open" event, but it does not run the check. However if I open the form, go to design view, and the toggle back to form view it works perfectly. What event can I enter the code into so I don't have to leave form view and go back. I am using Access 2002.

Dim x As Integer

x = RecordsetClone.RecordCount

If x > 1 Then
MsgBox "More than 1 record"
Else
End If
 
The on open event happens before the on load event. Basically the form is created then it loads the data. So there are no records yet loaded. move it later.

When you first open a form, the following events occur in this order:

Open → Load → Resize → Activate → Current

The Load event occurs when a form is opened and its records are displayed

If you're trying to decide whether to use the Open or Load event for your macro or event procedure, one significant difference is that the Open event can be canceled, but the Load event can't. For example, if you're dynamically building a record source for a form in an event procedure for the form's Open event, you can cancel opening the form if there are no records to display.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top