Without seeing your code i think your problem is your use of your recordset
variables.
There are a few ways to open multiple recordsets in one sub. One way is to
open the recordset, get your data, close the recordset, and then reopen a new
recordset. Another way is to make two recordsets.
I will show you how to do both of the methods i just talked about.
This is how you close and reopen a recordset:
Dim rs As ADODB.Recordset
Dim sSQL As String
Dim strLastName as String
On Error GoTo hell
Set rs = New ADODB.Recordset
editper = Forms![requests]![Subrequests].Form![StaffID]
sSQL = "SELECT firstname, lastname " & _
"FROM Customers " & _
"WHERE customers.CustID = " & editper
rs.Open sSQL, CurrentProject.Connection, adOpenStatic
If rs.RecordCount > 0 Then
custname = rs!firstname & "." & rs!Lastname
strLastName = rs!Lastname
End If
'close the first recordset so you can reopen and new query useing the same
variable "rs"
rs.Close
sSQL = "SELECT firstname, lastname " & _
"FROM Customers " & _
"WHERE customers.lastname = " & strLastName
rs.Open sSQL, CurrentProject.Connection, adOpenStatic
If rs.RecordCount > 0 Then
custname = rs!firstname & "." & rs!Lastname
End If
'always close the recordset after you are done with it
rs.Close
Set rs = Nothing
Exit Sub
hell:
MsgBox Err.Description
This is how i would do it with two recordsets:
'set up two variables for each recordset
Dim rs As ADODB.Recordset
Dim rs2 As ADODB.Recordset
Dim sSQL As String
On Error GoTo hell
Set rs = New ADODB.Recordset
editper = Forms![requests]![Subrequests].Form![StaffID]
sSQL = "SELECT firstname, lastname " & _
"FROM Customers " & _
"WHERE customers.CustID = " & editper
'open the first recordset
rs.Open sSQL, CurrentProject.Connection, adOpenStatic
If rs.RecordCount > 0 Then
custname = rs!firstname & "." & rs!Lastname
'now if you have data then open the second recordset
Set rs2 = New ADODB.Recordset
sSQL = "SELECT firstname, lastname " & _
"FROM Customers " & _
"WHERE customers.lastname = " & rs!Lastname
rs2.Open sSQL, CurrentProject.Connection, adOpenStatic
If rs2.RecordCount > 0 Then
custname = rs2!firstname & "." & rs2!Lastname
End If
'make sure you close both recordsets when you are done.
'HERE
rs2.Close
Set rs2 = Nothing
End If
'and HERE
rs.Close
Set rs = Nothing
Exit Sub
hell:
MsgBox Err.Description
I hope this helps you with your bug.
Good Luck!
TallyJasin said:
I am having a problem executing this twice in an event procedure. I first
check one table for certain values and then I check another table for certain
values. I am still trying to get the code corrected in my procedure but it
either tells me that I have a Duplicate declaration in current scope or no
value given for one or more required parameters.