Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between the "On Open" event and the "On Load" event for a data-entry Form

Tags:

vba

ms-access

I have designed a data-entry Form for conducting a survey. For each survey question, only one answer can be selected from a list of multiple-choice answers. I have used an "Option group"(a set of radio buttons)Control for each set of multiple-choice answers such that each possible answer within the set has a radio button beside it which when clicked, would select that answer. Whenever the form is initially displayed(I'm not sure whether to say "opened" or "loaded") for use, I want each "Option group" to have none of its answers selected. I know the VBA code to use to achieve this. I wish to know the difference between the "On Load" event and the "On Open" event for any data-entry Form. After knowing the difference, I will know and understand which of these two events to apply the VBA code to.

like image 860
I Mosbee Avatar asked Dec 14 '22 12:12

I Mosbee


1 Answers

Open

Open happens before Load and allows you to cancel so it doesn't open. It also allows access to OpenArgs. This can be helpful if your form requires user input. If it is not supplied, you can cancel the Form.Open or prompt the user for needed values.

Private Sub Form_Open(Cancel As Integer)
     If "" & OpenArgs = "" Then
         Cancel = True
         Msgbox "Open Arguments are required"
     End If 
End Sub

Load

Load happens after Open and lacks any of the control Open provides.

Private Sub Form_Load()
    Me.Caption = Date
End Sub

You may want to use both Events. Use Open to get the input parameters, and use Load to set the values of controls based on those supplied parameters.

References

  • Form.Open Event
  • Form.Load Event
like image 196
Don Jewett Avatar answered Jan 19 '23 01:01

Don Jewett