resetting in in module variable

icemonster

Registered User.
Local time
Today, 13:38
Joined
Jan 30, 2010
Messages
502
so basically all this time i have been assigning pk that've been pulled through sql through a text box, i realized you can actually do this via variable. so i have been playing around with it and got it to work, but what i want to do is, how do i reset it once the form closes? here's a sample of my code

Code:
Function startStudentEmailAddress()
strStartSql6 = "SELECT qry_contact_info_student1.id_contact_info_student, qry_contact_info_student1.continfostud_id_student, " _
             & "qry_contact_info_student1.continfostud_id_contact_info, " _
             & "qry_contact_info_student1.continfo_def, qry_contact_info_student1.continfo_id_type FROM qry_contact_info_student1 "


strWhereSql6 = "WHERE qry_contact_info_student1.continfostud_id_student = " & Forms![frm_main_menu]![lstStudent] & " "
strWhereSql6 = strWhereSql6 & "AND qry_contact_info_student1.continfo_id_type = 3"

strSQL6 = strStartSql6 & strWhereSql6

Set rs = CurrentDb.OpenRecordset(strSQL6)

With rs

If rs.RecordCount > 0 Then

IDContactInfo3 = !continfostud_id_contact_info '<--- this is the FK assigned to variable
Me.txtemailaddress = !continfo_def
Me.txtemailaddressid = IDContactInfo3

Else

Me.txtemailaddress = Null

End If

End With

Set rs = Nothing

End Function
 
Variables within your Module have a limited life. Unless you save the data to your table, then you shouldn't have any problems with your Tables.

Close the recordset in your code, as it appears you have done.
 
so i'm all good right? when closing the form the variable is gone?
 
Have you any bad experiences to indicate otherwise ?

If the code is behind a Form, then it should be Dead when the form is closed.

If the code sets up a Global Variable and or a TempVar then, the Variable will still be alive but you should know if you have done such a thing as it is not possible to do it by accident.

Good coding is to Close recordsets at the end of the code and if you have setup a TempVar and no longer need same then Remove this but again, you should be aware if this is the case.

Most :eek: issues will be if your code has done some changes to your table data that you did not expect. If so, then closing the form willnot resolve this.

Variables in your code are not changes to your tables - unless you code such a change to take place by way of Insert, Update, Delete etc but again, you should be aware of such and check your code on sample data before venturing forth where angles fear to tread.:)
 

Users who are viewing this thread

Back
Top Bottom