Full Version: Form Events (Controls) not working as expected, help!
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
larai
I have a form with a checkbox control on it. When I click on the checkbox, if it is "true" I open a popup form where the user enters specific data into 2 controls. When the user clicks on an OK command button, a value is stored to a public variable and then the popup is hidden.

So...in form A, I have the checkbox. In the before update event, if the checkbox is "true" then the popup form B opens. After the popup form B stores a value to a public variable blnOK then I expect that the next line of code in the form A checkbox before update event should run.

Rather, what is happening is the ENTIRE beforeupdate code runs (even though the popup has opened)...after the before update event ends, THEN the code in the popup OK command button runs, at which point, it is too late.

I use the before update event because if blnOK is false, then I want to undo the checkbox true.

Am I using the wrong event/events to do this? Code for the before update event is pasted below.

Private Sub chkS6MfgSignoff_BeforeUpdate(Cancel As Integer)


If Me.chkS6MfgSignoff = True Then
If IsNull(Me.txtSoftwareVers) Or Me.txtSoftwareVers = "" Then
MsgBox "You must enter the Software version to continue", vbOKOnly + vbExclamation, "Error"
Cancel = True
Me.chkS6MfgSignoff.Undo
Else
DoCmd.OpenForm "frmSelectUser"
'***I would think that the code behind the click event on the OK command button on frmSelectUser would occur here. If I step through the code with breakpoints set, control DOES pass to the frmSelectUser, if I select the module and continue to F8. If I do not select the frmSelectUser module, it continues to step through the beforeupdate event on form A
If blnOK = True Then
Me.txtS6MfgSignoffRecBy = Forms!frmSelectUser.cboUserID.Value
Me.txtS6MfgSignoffDate = Now()
Me.tabCSU5.Visible = True
blnOK = False
DoCmd.Close acForm, "frmSelectUser"
Else
Cancel = True
Me.chkS6MfgSignoff.Undo
End If
End If
Else
Me.txtS6MfgSignoffRecBy = ""
Me.txtS6MfgSignoffDate = ""
Me.chkS6MfgSignoff.Locked = False
Me.tabCSU5.Visible = False
End If

End Sub
Jack Cowley
Since you are not opening your form in acDialog mode the code continues to run even though you have opened a new form. This code will open your form and not continue the rest of your code until the form closes:

DoCmd.OpenForm "frmSelectUser", , , , ,acDialog

You may want to consider the After Update event of the check box and not the On Click event... I was unsure if this is what you are doing, so I may be wrong.

hth,
Jack
fiftyfour
What software version are you trying to return? If its Access, you can use code to return that value and therefore you will not need to query the user for it.
larai
Jack, you are a genius, thank you so much!!

Works like a charm now.

I was using the before update event and that event because I want to cancel (unclick) the checkbox if the User does not enter the information properly on the 2nd form.
larai
And it's not asking for the software version of anything on the local machine, it's to show the configuration of a product that we manufacture. The user isn't being queried for the software version; it's a textbox on the same form as the checkbox.
Jack Cowley
You are very welcome and I assume that all is working now as you want. Continued success with your project...

Jack
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.