Full Version: Question about Pbulic Variables
UtterAccess Forums > Microsoft® Access > Access Forms
djcox100
Sorry for posting this in two different locations, but no one replied to my first post, so I figure I got it wrong....
uick why raher than how question. I have the following code on a pop-up dialog form I created:
Private Sub lstContactValue_DblClick(Cancel As Integer)
Dim tmpSQLLink As String
tmpSQLLink = "some SQL statement"
DoCmd.RunSQL tmpSQLLink
DoCmd.OpenForm "frmDone", , , , , acDialog 'This dialog simpy tells the user the operation is complete and closes after 1 sec.
DoCmd.Close acForm, "frmMatchingContact", acSaveNo
tmpContactMatchAction = False
End Sub
The variable, "tmpcontactMatchAction" is used by the underlying form which initiates a function which ultimately opens the form, "frmMatchingContact". In this version of code, the procedure works as it should. but if I move the line, "tmpContactMatchAction = False" to the following position:
DoCmd.RunSQL tmpSQLLink
tmpContactMatchAction = False
DoCmd.OpenForm "frmDone", , , , , acDialog 'This dialog simpy tells the user the operation is complete and closes after 1 sec.
DoCmd.Close acForm, "frmMatchingContact", acSaveNo
For some strange reason, tmpContactMatchAction is set to "TRUE". Is this because I'm opening and closing another form after the variable is assigned?
vtd
No ... opening and closing [frmDone]should not affect the value of tmpContactMatchAction unless you actually have some code in this Form to change the value of the variable, assuming that the scope of the variable is appropriate.
It sounds to me that you have some other process that changes the value of this variable??? Check the scope of the variable and seach your code for the relevant assignment statement.
djcox100
Ok I get it. The form "frmMatchingContact" has an "On Close" event which assigns the value as true. So that explains why it is tripping the value to True when the line - DoCmd.Close acForm, "frmMatchingContact", acSaveNo is execute.
I have another question - what is the difference between the events, "On Load" and "On Close"?
theDBguy
I believe:
On Close fires when the form is closed, and
On Load fires after the form opens and the data is loaded to the form (for bound forms).
Hope that helps...
djcox100
Actually, sorry...I made a mistake. I meant, what is the difference between "on load" and "on open"? Sorry for the confusion...
theDBguy
No problem. sad.gif
When the form opens, the On Open event fires, then the data is loaded onto the form (if it's bound) - that's when the On Load event fires.
Hope that helps...
vtd
Hi theDBGuy
That may not be entirely true. If you put a break in the Form_Open Event of a bound Form and use the Immediate window to check, you will find that the values of the Fields have already been retrieved.
Oalways think of the 2 events are nearly the same except that the Open Event can be cancelled and the Load Event cannot be cancelled.
Cheers
djcox100
Cool, thanks everyone for your explanation.
vtd
You're welcome... Glad we could assist...
theDBguy
You're welcome! Good luck with your project.
Thanks Van for the extra info. thumbup.gif
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.