Private Sub Form_Current()
MsgBox "First on Current"
Me.OnCurrent = "=fncCurrentEvent()"
End Sub
Private Function fncCurrentEvent()
MsgBox "Subsequent current events"
End Function
Change the event handler after the first on current to the function
I like to use Toggle Button controls in place of checkboxes because they have an inherent Yes/No state like checkboxes but are more flexible to format and size. BUT...I want to show an image ONLY when the state is -1 (True) and not show an image otherwise. So how do you turn on and off an image in a Toggle Button based upon its state?
It turns out Toggle Buttons can read and use images from other Toggle Buttons. So the Toggle button bound to your Yes/No field on your form can use an image from another Toggle button when its state is True and not use it when its state is False.
I like to be able to select specific individual records to print using a Yes/No field, so I:
Created a Yes/No Data Type field in my table
Added one Toggle button on my form bound to the Yes/No field with No Image
Added another Toggle button on my form that is hidden and holds the image I want to use in its image property. In my case, the image is the native ACCESS Printer image like this
So the first record on my customer form looks like this if I want to include Customer A records in my print query:
And looks like this if I don't want to include Customer A:
My bound Toggle button is named CustomerSelection and the Toggle button that contains the image is named CustomerSelectImage
The code I use to Turn on the image if the state is True and turn off the image if the state is False is:
Code:
Private Sub Form_Current()
Call CustomerSelection_Click
Exit Sub
End Sub
Private Sub CustomerSelection_Click()
If Me.CustomerSelection = -1 Then
Me.CustomerSelection.PictureData = Me.CustomerSelectImage.PictureData
Else
Me.CustomerSelection.PictureData = Null
End If
Me.Form.Recalc
Exit Sub
End Sub
As you can see, it uses the PictureData property of the Toggle button that holds the image.
Setting the image to Null when the state is False was just blind luck. I tried =Null and it worked. Sometimes you just get lucky.
Notice you need to refresh things when you move from record to record with the Form Current Event