Enable CommandButton from another Form

luzmen

Registered User.
Local time
Yesterday, 16:30
Joined
Jul 6, 2017
Messages
10
Hello...

The situation is this:
I have 2 Forms (let say frmBox1 and frmBox2). In frmBox1 i have CommandButton1 that I set the Properties>Data>Enabled = No.
In frmBox2, i have CommandButton2 to open frmBox1.

I want to insert a VBA code in CommandButton2 to Enabled=Yes the CommandButton1 before the code to open frmBox1.

I tried this code:
Code:
Forms("frmBox1").CommandButton1.Enabled = Yes
.. but i have run-time error '2450': Microsoft Access cannot find the referenced form 'frmBox1'.

Hoping there is a kind heart to help me out this small problem.

Thank you in advance...
 
You need to open the form before you can do anything in it.
 
the form needs to be open for access to be able to see it - put the code after you have opened the form.
 
The form would have to be open for you to change a controls state.

If the form can be opened from different forms then I would use the OpenArgs property to pass the calling forms name and enable /disable the control based on that.

So to open it

Code:
Docmd.OpenForm "frmBox1", acNormal, , , , , "frmBox2"

And then in the on load property of frmBox1 put

Code:
If Me.OpenArgs = "frmBox2" Then 
       CommandButton2.enabled = True
Else 
       CommandButton2.enabled = False
End If
 
Thank you so much guys...

I just put the code to enable the CommandButton1 after the code to open the form, and change the =Yes to =True.

Once again thank you so much.
 
not sure you have changed anything. Booleans have the value of -1 and 0 which can also be displayed as True/False, Yes/No

So True and Yes are the same thing
 

Users who are viewing this thread

Back
Top Bottom