cyberpac9
Registered User.
- Local time
- Today, 13:18
- Joined
- Jun 6, 2005
- Messages
- 70
i have a form (frm1) and subform (sfrm1) that when a room number is double-clicked in the subform another form (frm2) and subform (sfrm2) loads. frm1 has building info and frm2 is used for inspection info. if a room has never been inspected then when frm2 loads the field [room] will be empty. however, after the first inspection the room number is obviously entered for frm2.
so i have created a global variable that holds the value of [lab_room] from frm1 and is supposed to use this value on frm2 if the room has never been inspected - ie, [room] is null. however, the value of intRoom (global variable) is lost after is leaves frm1 and goes to frm2. below is my code:
can anyone see why the value is being lost from frm1 to frm2? i'm ripping my hair out trying to figure this one out....
so i have created a global variable that holds the value of [lab_room] from frm1 and is supposed to use this value on frm2 if the room has never been inspected - ie, [room] is null. however, the value of intRoom (global variable) is lost after is leaves frm1 and goes to frm2. below is my code:
Code:
[B]modGlobal (module with global variables declared)[/B]
Option Compare Database
Global intVar As Variant
Global intRoom As String
Private Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid) As Long
Private Type GUID 'Memory structure used by CoCreateGuid
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Const S_OK = 0 'Return value from CoCreateGuid
[B]frm1 subform double click event[/B]
Private Sub Form_DblClick(Cancel As Integer)
On Error GoTo Err_DblClick
Dim stDocName As String
Dim stLinkCriteria As String
Dim stMsg As String
'if the user double clicks on an area that has no lab_id associated with it
'prevents a null value for lab_id
If IsNull(Me!lab_id) Then
stMsg = "There is no lab associated with this room."
intRes = MsgBox(stMsg, vbOKOnly + vbExclamation, "Error - No Lab Selected")
GoTo Exit_DblClick
End If
'opens lab forms associated with this lab_id
intVar = Me!lab_id
intRoom = Me!lab_room
stDocName = "ehs_lab_safety_surveys"
stLinkCriteria = "[lab_id]=" & "'" & intVar & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
[Forms]![ehs_lab_safety_surveys].Form.RecordsetClone.Find ("lab_id = '" & intVar & "'")
DoCmd.Close acForm, "copy_lab_search_by_bldg"
Exit_DblClick:
Exit Sub
Err_DblClick:
MsgBox Err.Description
Resume Exit_DblClick
End Sub
[B]frm2[/B]
Private Sub Form_Load()
Dim strNewguid As String
'checks for null values of lab_id, room, id and safety_survey_date. if they are
'null or empty a value is inserted.
If IsNull(Me!lab_id) Or (Me!lab_id = "") Then
Me!lab_id = intVar
End If
If IsNull(Me!room) Then
Me!room.Value = intRoom
End If
If IsNull(Me!safety_survey_date) Then
Me!safety_survey_date = Date
End If
If IsNull(Me!id) Or (Me!id = "") Then
Set x = CreateObject("Scriptlet.TypeLib")
strNewguid = Left(x.GUID, 38)
Me!id.Value = strNewguid
End If
DoCmd.Maximize
End Sub
can anyone see why the value is being lost from frm1 to frm2? i'm ripping my hair out trying to figure this one out....