I created a subprocedure that includes a recordset as follows:
Private Sub Combo17_Click()
'Declaring object and string variables
Dim DB As Database
Dim rec As Recordset
Dim sDealName As String
'Assign Object variable to current database
Set DB = CurrentDb
'Assign object variable to recordset
Set rec = DB.OpenRecordse t("qryName", dbOpenDynaset)
'Comparison of value from user to recordset
rec.FindFirst "[EmployeeID] =" & Nz(Me!Combo17.V alue, 0)
'If no match is found, user receives error message _
'exit routine
If rec.NoMatch Then
MsgBox "Check your entry", vbCritical, "No Matches"
Me!Combo17.Valu e = ""
Exit Sub
Else
' If record is found, value entered by user is passed to variable sFirstName
sDealName = Nz(rec.Fields(" Firstname"), "")
If sDealName = "" Then
MsgBox "Your sDealName does not exist"
Me!Combo17.Valu e = ""
Exit Sub
End If
End If
rec.Close
End Sub
The problem is that the variable sDealName loses scope when I close the recordset. I need to pass the value from this sDeal variable to another subprocedure.
Thank you.
Private Sub Combo17_Click()
'Declaring object and string variables
Dim DB As Database
Dim rec As Recordset
Dim sDealName As String
'Assign Object variable to current database
Set DB = CurrentDb
'Assign object variable to recordset
Set rec = DB.OpenRecordse t("qryName", dbOpenDynaset)
'Comparison of value from user to recordset
rec.FindFirst "[EmployeeID] =" & Nz(Me!Combo17.V alue, 0)
'If no match is found, user receives error message _
'exit routine
If rec.NoMatch Then
MsgBox "Check your entry", vbCritical, "No Matches"
Me!Combo17.Valu e = ""
Exit Sub
Else
' If record is found, value entered by user is passed to variable sFirstName
sDealName = Nz(rec.Fields(" Firstname"), "")
If sDealName = "" Then
MsgBox "Your sDealName does not exist"
Me!Combo17.Valu e = ""
Exit Sub
End If
End If
rec.Close
End Sub
The problem is that the variable sDealName loses scope when I close the recordset. I need to pass the value from this sDeal variable to another subprocedure.
Thank you.
Comment