changing visibility property from a different form

JJSHEP89

Registered User.
Local time
Today, 12:58
Joined
Aug 18, 2016
Messages
121
I've searched quite a bit but i guess i'm not using the right terms so i'll post here. if there's an existing post that solves this please share.

I have a label and textbox control on an "Entry_Maintenance" form that i am wanting to toggle the visibility on and off depending on the action taken to open the form. (example: creating new entry, updating existing etc.) I have a series of events that open the same form and simply populate it with current records for updating or a blank entry for creating new. However i am trying to control the visibility from within the click even on a separate form, after the DoCmd.Openform "Entry_Maintenance". Im not sure how exactly to change properties on non-active forms. This is what i have but its obviously not working. can someone please enlighten me?

Code:
DoCmd.OpenForm "Entry_Maintenance", acNormal, , "DML_ID =" & Me.lstRecentEntries.Column(0, ListIndex + 1), , acDialog
        Me.txtDML_ToolNumber.Visibility = True
        Me.lblDML_ToolNumber.Visibility = True
 
Well, you'd need the full form syntax to reference another form, but since you're opening the form with the acDialog option, the following lines won't run until the form is closed or hidden anyway. It's also Visible, not Visibility.

Forms!FormName.ControlName.Visible = True
 
It's also Visible, not Visibility.

Forms!FormName.ControlName.Visible = True

wow, total noobie move there, been one of those days. :banghead:

I think i have a different approach that i'll try. in the meantime is there another method for opening forms that would allow the next line to execute before the form is closed?
 
Simplest is to drop the ", , acDialog" from the end. If you need dialog mode, probably passing something in OpenArgs to determine which controls to hide if they can vary.
 
so the workaround i did for this was to simply create a global variable called varAction, that is set to Create, Read, Update, Delete. Each on load event of the forms looks at the varAction and determines which controls need to be visible. the variable is then set to empty when the form is closed.

this is working for me but is a variant datatype the way to go for my variable? i feel like theres a more efficient way of doing this, not that memory is a concern for my small application, but it would be nice to learn the most efficient means of doing this.
 
Simplest is to drop the ", , acDialog" from the end. If you need dialog mode, probably passing something in OpenArgs to determine which controls to hide if they can vary.

so when i drop the dialog, the form then pop's up but immediately disappears, I have pop up set to yes and I've tried Modal set to both yes and no, with the same result.
 
Use the form's own events to determine whether to show or hide controls. In the Current event, you can check to see if the current record is "new" or existing.

If Me.NewRecord Then
Me.SomeControl.Visible = True
Else
Me.SomeControl.Visible = False
End If
 
To be clear when you open a form acDialog code execution stops in the calling form at that moment. It does not resume until after the called form is closed (or hidden). This can be very useful for managing flow of actions. You can continue an action (like requery the calling form) in the calling form once the pop up is closed. However, since code is halted in the calling form the calling form cannot manipulate the called form. With all other methods of opening a form (even if that form is a dialog modal form) code continues in the calling form. This is useful because you can set properties in the called form.

Normally if you want to pass information to the called form when it is acDialog you use openArgs in the open form method. This allows you to pass in a string. You could pass in "Create, Delete, Edit,..." or something like a user ID. Then you can use something like a Select Case in the called forms on load event to determine which actions to take.
Select Case Me.OpenArgs
Case "Delete"
... do stuff
Case "Edit"
... do stuff
Case "x Priveledges"
... do stuff
end select

If you want to send in multiple pieces of information you can send it in a delimited string and parse the string
"User1; Edit; ReadOnly"

For the most part this is better than using a global variable/s. However it is limited because you are passing in strings and not objects. So I cannot pass in a recordset to the called form. I would have to use the global variable technique.

Again the only time I need to "pass" anything is if I open acDialog. Any other time I can control from the calling form.
 

Users who are viewing this thread

Back
Top Bottom