Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Command Button

Status
Not open for further replies.

pbrown2

Technical User
Jun 23, 2003
322
US
I would have thought this would be rather easy, but Access has other ideas...

Basically,
(2) forms.
Switchboard1
Switchboard2

Switchboard1 has (3) buttons
TN
MS
CA

Switchboard2 has an unbound text box named Facility

When the user clicks (on Switchboard1), TN
the unbound text box reads "TN", if MS is clicked, "MS" appears in the unbound text box and so on.

The problem:
Switchboard2 has several options and there is a need to disable certain command buttons based upon which location is choosen.
Therefore, I have tried the following in the On Load, On Open, On Current and On Activate (One at a time).

If Me.Facilitiy = "CA" or Me.Facility = "TN" then
[Gulf].Enabled = False
else
end if

However, nothing seems to be working and the button is never disabled. In an attempt to see where the problem is, I changed the code to a msgbox to the below:
If Me.Facility = "CA" Then
MsgBox "OK"
Else
MsgBox "Not OK"

Then I went to form1 and clicked CA, however the "Not Ok" box appeared...

Any ideas???



Thank you for any and all help,

PBrown
 
Try using the complete form name reference instead of Me.

Forms![FormName].Facility="CA"

It appears that the Me reference may be referencing the wrong form which is causing the rest of your logic to fail.

HTH,


Steve
 
Tried:
Private Sub Form_Load()
If Forms![Switchboard2].Facility = "CA" Then
[Gulf].Enabled = False
End If

End Sub

Also,

Private Sub Form_Load()
If Forms![Switchboard2].Facility = "CA" Then
Forms![Switchboard2].[Gulf].Enabled = False
End If

End Sub

However, it does not work either.

Could it have something to do with the fact that Facility is an unbound text box that is being filled in via the form Switchboard1 when the user clicks the button???

From Switchboard1:

Private Sub CA_Click()
DoCmd.Close
DoCmd.OpenForm "Switchboard2"
Forms![Switchboard2].[Facility] = "CA"
End Sub


I am almost at my wits end over this...... Any other ideas??


Thank you for any and all help,

PBrown
 
The Load, Open, and Activate events of Switchboard2 won't work because they occur before Facility receives the value "CA".

An alternative might be to have a combo box with the state choices in it, with only one button to 'Continue' or whatever. Then you could set the value of the Facility text box equal to the value of the combo box.

-Gary
 
Try this -

Private Sub CA_Click()
'DoCmd.Close
DoCmd.OpenForm "Switchboard2"
Forms![Switchboard2].[Facility] = "CA"
End Sub


If it works then have Switchboard2 close Switchboard1.

If this works, then what was occurring was you were attempting to use a reference to a form that was not available because it was closed.


HTH,


Steve

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top