Checkbox on one form disable button on another form

D

datahead22

Howdy Gang,

I have a check box on one form that if it is checked I need it to
disable a button on another form.
I have the following event on the second form:


Private Sub Form_Current()
If Me!chkbxemerg_serv_contact1 = True Then
Me!Command88.Enabled = False
End If
End Sub

I have brought this check box chkbxemerg_serv_contact1 into the second
form and hidden it so that the if statement has the field to refer to.
I thought it was working but apparently when you first enter the second
form even if the check box is False the button is still disabled.
However if you go back to the first form and then come back to the
second form suddenly the button is enabled.

Not sure that made any sense. But I'm really confused about what is
happening now.
Any ideas would be Awesome!
Thanks Again!
 
D

Douglas J Steele

To refer to a control on another form, you need to refer to the other form.
"Me" is always the current form.

Assuming chkbxemerg_serv_contact1 is on a form named Form1, you'd use:

Private Sub Form_Current()
If Forms("Form1")!chkbxemerg_serv_contact1 = True Then
Me!Command88.Enabled = False
End If
End Sub

Of course, to handle changes, that should really be:

Private Sub Form_Current()
If Forms("Form1")!chkbxemerg_serv_contact1 = True Then
Me!Command88.Enabled = False
Else
Me!Command88.Enabled = True
End If
End Sub

or, simpler,

Private Sub Form_Current()
Me!Command88.Enabled = Not Forms("Form1")!chkbxemerg_serv_contact1
End Sub

Note that you're get an error if you try running this code and Form1 isn't
open.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top