If statment vba button appear. (1 Viewer)

Afrooman108

New member
Local time
Today, 19:28
Joined
Apr 23, 2012
Messages
9
I need an if statment that will show a button if a subform number is above 500.

The button is called 'Pass'
The subform is called 'Agesubform'
The field that will be over or less than 500 is called 'Days Employed' it is on a query called 'age' and also the subform above mentioned.

I

Here is what I have so far, it doesn't work.

age.Daysemployed = ">=500" Then
Pass.Visible = True
Pass.OnClick = "Age_subform.Visible = False"
Pass.OnClick = "Pass.Visible = False"
 

Beetle

Duly Registered Boozer
Local time
Today, 12:28
Joined
Apr 30, 2011
Messages
1,808
Is the button on the main form or the subform?

If it's on the subform, what type of form (Single, Continuous, etc.) is the subform?
 

Afrooman108

New member
Local time
Today, 19:28
Joined
Apr 23, 2012
Messages
9
It is on the main form.
 

VilaRestal

';drop database master;--
Local time
Today, 19:28
Joined
Jun 8, 2011
Messages
1,046
To set the visibility of the button and reshow the subform from any previous hiding of it:

Code:
Private Sub Form_Current()
   Pass.Visible = (Age_subform.Form.[Days Employed] >= 500)
   Age_subform.Visible = True
End Sub

The Current event happens each time the form moves to a different record (including when it's first opened).

To hide the subform when the button is clicked:

Code:
Private Sub Pass_Click()
    Age_subform.Visible = False
End Sub

All in the module of the main form.

To hide the Pass button when the Pass button is clicked will need to set the focus to another control first: you can't hide a control that has the focus and it will have the focus because it's just been clicked.

I have never set the OnClick property of a control at runtime. I doubt you want to. That is not how to run code when a button is clicked.
 
Last edited:

Afrooman108

New member
Local time
Today, 19:28
Joined
Apr 23, 2012
Messages
9
When I tried it I got this:


This error occurs when an event has failed to run because Microsoft Office Access cannot evaluate the location of the logic for the event. For example, if the OnOpen property of a form is set to =[Field], this error occurs because Access expects a macro or event name to run when the event is fired.
 

Users who are viewing this thread

Top Bottom