There are a couple of ways to do this. I would put a text box on the form, hide it, and then when the first button was clicked, add a 1 to the text box. Then when the second was clicked, change it to 2, etc. When the close form button is clicked, have it check the value in the hidden check box and if it does not = 5, have it pop up a message box, and then Exit Sub, else, do whatever it is supposed to do.
The problem with the other issue of making the buttons inactive based on their own click event is that they can't be set to inactive while they have focus. SO...
When each button is clicked, add this code (pretend you have a field on the form that should have focus first called Me.PKID):
Button1_Click()
...
Me.PKID.SetFocus
Then, on the On Got Focus event of the PKID field, add this code:
Me.Button1.Enabled = False
However, you are going to need to do flow control to have the On Got Focus event Also check the hidden text field. So, for the On Current event of the form, I would put this code:
Me.HiddenTextField = 0
That sets the text field to 0 since no buttons have been clicked yet.
Then on the On Got Focus Event of the PKID, or whatever field gets focus first on the form, add this code:
Dim iButton As Integer
iButton = Me.HiddenTextField
Me.Button1.Enabled = False
Me.Button2.Enabled = False
Me.Button3.Enabled = False
Me.Button4.Enabled = False
Me.Button5.Enabled = False
Select Case iButton
Case 0
Me.Button1.Enabled = True
Case 1
Me.Button2.Enabled = True
Case 2
Me.Button3.Enabled = True
Case 3
Me.Button4.Enabled = True
Case 4
Me.Button5.Enabled = True
End Select
This will set all the buttons to disabled, and then enable the one that should then be enabled. If no button has been clicked yet, then first button will be enabled and all the others disabled. If the first one has been clicked, the second one will be enabled and all the others disabled, etc.
Did that help any?
mmcdonal
|