Warning Banner Check box makes accept button visible

TylerTand

Registered User.
Local time
Today, 10:08
Joined
Aug 31, 2007
Messages
95
I have a form that will be the warning banner entry point to my database. The Form will have an explanation of the rules and then a check box("ckAccept") if you agree to the rules. I want to make it mandatory that you check the box before you are able to see the Accept button to go into the database. I found this code but it doesn't seem to work.

Private Sub ckAccept_Click()

If Forms![WarningBanner]![ckAccept] = True Then
Me.Accept.Visible = True

Else
Me.Accept.Visible = False

End If
End Sub

I have set the Accept button to be invisible to start and want it to be visible after the check box is checked. Can you guys help me correct my VBA? Thanks for the help.:)
 
There is no reason to go through the Forms collection but your code should have worked anyway. What is it doing? I think it would look better if you just changed the Enabled property instead of the visible property.
Code:
Private Sub ckAccept_Click()
   If Me.ckAccept Then
      Me.Accept.Visible = True
   Else
      Me.Accept.Visible = False
   End If
End Sub
 
Last edited:
Agreed with RG here. Use an enabled instead as that's much more common. Here it is both ways in one line each:

Visible (it's invisible but enabled on the form load):
Me.ckAccept.Visible = Switch(Me.ckAccept, True, True, False)

Enabled (make it visible but disabled on the form load):
Me.ckAccept.Enabled = Switch(Me.ckAccept, True, True, False)
 
I'm Retarted. (Now I can move on)

I need more help. I thought I could just put the code
Me.ckAccept.Enabled = Switch(Me.ckAccept, True, True, False) below the Private Sub Check_Click() and above the end Sub and it would work. I think I have a fundamental flaw in how to apply the code. To me this code reads, when the check box (ckAccept) is checked, switch the enabled/disabled properties so that it is initially disabled and changed to enabled after the box is checked. So I tried this. It didn't work. If I disabled the actual Accept button and closed the form and re-opened it, once I put a check in the box, the button was still disabled. This is the full code I used:
Private Sub Check_Click()
Me.Command2.Enabled = Switch(Me.Command2, True, True, False)
End Sub

What am I doing wrong? I thought the code should go behind the check box since the actual accept button has a macros that closes the warning banner and opens another form. Does the label of the Accept box have anything to do with this? This is really frustrating since I didnt' think this would be complicated. I appreciate your help straightening me out with this one. Thanks.
 
I almost forgot, I am using Access 2007 if that has any bearing on the problem. I had a programmer at my house and he is used to using 2003 and he came up with this code:

Private Sub ckAccept_Click()

If Forms![frmHide]![ckAccept] = True Then
Me.cmdAccept.Visible = True
Me.lblAccept.Visible = True

Else
Me.cmdAccept.Visible = False
Me.lblAccept.Visible = False

End If
End Sub

The check box was named: ckAccept and the actual button was cmdAccept. This didn't work on 2007. I will try it tomorrow when I get to work on 2003. I wouldn't think the version of Access would make a difference, but maybe this is the problem?
 
This will work in 2003 and 2007. (There's no difference really.) Look at the sample. This should answer your questions.

EDIT: Err, forgot. Open the form f_Main (the only form and object in the DB) to see this working. I'm using Enabled instead of Visible for the reasons stated above, but the effect is identical.
 

Attachments

Last edited:

Users who are viewing this thread

Back
Top Bottom