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!

Referencing a variable from a different form

Status
Not open for further replies.

Swiftraven

Technical User
Oct 29, 2001
28
US
Hi all,

I have a form that acts like a switchboard. In the VB code, I have declared a boolean variable that I set when one of the buttons is clicked. These buttons open another form and I want to control what fields are locked in that form depending upon which button is clicked on the first form.

On the first form, I declare the variable as:

Dim Manager As Boolean
and for each buttons on_click, set it either to True or False, then open the other form and then close the current form (though I have tried it without closing the current form, neither works).

On the resulting form, in the form open event, I have the following code

Private Sub Form_Open(Cancel As Integer)
If Forms![frm_FormSelection]![Manager] = False Then
Me![Budget].Disabled
Me![Actuals].Disabled
ElseIf Forms![frm_FormSelection]![Manager] = True Then
Me![Budget].Enabled
Me![Actuals].Enabled
End If
End Sub

Its erroring on the Manager section saying it can't find the field. I assume this is because it is looking for a control and not a variable. I need to be able to check the variable to determine the state of the form when its opened.

Thanks for any help

Jason
 
Declare your Manager variable as a Public variable in a VB Module (not a form module, an independant module).
If you have not, create a new one only with the declaration of the variable.
>>Public Manager As Boolean

Then, do not declare it on any modules attached to your both forms. Is should run!
 
Thanks for the reply,

I created a Module called Management, inside I put only

Public Manager As Boolean

I also tried it as

Dim Manager As Boolean

but neither worked.
How do I reference that boolean and set it to true or false when the button is clicked.
Here is what I tried adding to the buttonclick subroutine to set it to false.

Modules![Management]![Manager] = False

but I get a compile error on the buttonclick sub routine stating that it I can't assign to read only property.

Thanks for the help

Jason
 
Figured it out :)

Thanks for the help Lozere.

Regards,
Jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top