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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modal Form Question 1

Status
Not open for further replies.

nag9127

Technical User
Mar 15, 2007
76
US
In Access 2000, I have a Receipt Form which allows the user in a particular control, to bring up a modal form using the Double_Click event of the control. The modal form provides for a numerical conversion and on closing sends the value to the same control from which the modal form was originally brought up. Presently, this is being done through code which sends the value to the named control in the Receipt Form. My question is whether there is some generic way to identify the originating control rather than having to specify it by its particular control name. This would allow me to apply the code to every instance where the modal conversion form is called up rather than having to individually program each form due to the different control names and form names from which the modal form is called. The control where the calculation is sent is always the same control that has the focus when the modal form is opened. Thanks for any help!
 
I normally do this with a global variable. In a standard module define your variable

public glblOriginatingControl as access.control

then before opening the form set the global variable

set glblOriginatingControl = screen.activeControl.name

Now in the closing of your modal form

glblOriginatingControl = some value
 
Thanks for the response MajP! I've not used global variables before but it all makes sense. I'll work on that this morning. A couple additional questions, once you set the global variable to a particular value, does it retain that value indefinitely or until it is changed elsewhere? I am concerned with setting the variable to a screen control in a subsequent form while it still has the value from a previous operation. Is there a technique that is commonly used to set it back to nothing or null or do I even need to worry about lingering values in a global variable?
 
For all variables you want to try to limit the life and scope. But with that said a few global variables can make things easier. Here is my technique.

1) In form "A", I my have a event to open a pop up form "B"
2) the event sets the gobal control, and opens the pop up form
3) I do something on the pop up form and in the on close of the pop up form I set the value of the global control to some value from the form. I then set the variable to nothing. Something like

Private Sub Form_Close()
glblControl.Value = Text0
Set glblControl = Nothing
End Sub

Also I made a mistake earlier I said
set glblOriginatingControl = screen.activeControl.name
I should have said
set glblOriginatingControl = screen.activeControl

I like to work with the actual control object then using the name of the control as a global variable. You could set the name of the control but this reduces flexibility because in you pop up you would have to reference the calling form. By using the control you do not need to know what form that control is on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top