G
Guest
Please Help…. I am at a loss… I have tried this a couple of different ways...
I have an unbound form where a user can input certain criteria,
click on a “Search†button (that fires the macro, that runs the code below)
which would then populate the subform with the recordset (results) based on
the criteria entered.
I am getting a “Compile Error: Invalid use of property†on
allRecords = CurrentDb.OpenRecordset(“qry_All_Documentsâ€, dbOpenDynaset)
What am I doing wrong?
Public Function Search() As String
‘Error Handling
On Error GoTo Err_Search_Click
'Establish connection to ActiveX Data Objects
Dim trs As ADODB.Connection
Set trs = CurrentProject.Connection
'Declare Recordset
Dim allRecords As New ADODB.Recordset
allRecords.ActiveConnection = trs
‘Determine which query we want to run based on User’s Criteria
If (Forms!Search_frm!Criteria_A is True AND
Forms!Search_frm!Criteria_B is True) Then
allRecords = CurrentDb.OpenRecordset(“qry_All_Documentsâ€, dbOpenDynaset)
End If
If (Forms!Search_frm!Criteria_A is False AND
Forms!Search_frm!Criteria_B is True) Then
allRecords = CurrentDb.OpenRecordset(“qry_Btype_Documentsâ€, dbOpenDynaset)
End If
‘Set Search_subform equal to allRecords
Set Forms!Search_frm!Search_subform.Form.RecordSource = allRecords
‘Shut down connection and recordset
allRecords.Close
Set allRecords = Nothing
Set trs = Nothing
Exit_Search_Click:
Exit Function
Err_Search_Click:
MsgBox Err.Description
Resume Exit_Search_Click
End Function
I have an unbound form where a user can input certain criteria,
click on a “Search†button (that fires the macro, that runs the code below)
which would then populate the subform with the recordset (results) based on
the criteria entered.
I am getting a “Compile Error: Invalid use of property†on
allRecords = CurrentDb.OpenRecordset(“qry_All_Documentsâ€, dbOpenDynaset)
What am I doing wrong?
Public Function Search() As String
‘Error Handling
On Error GoTo Err_Search_Click
'Establish connection to ActiveX Data Objects
Dim trs As ADODB.Connection
Set trs = CurrentProject.Connection
'Declare Recordset
Dim allRecords As New ADODB.Recordset
allRecords.ActiveConnection = trs
‘Determine which query we want to run based on User’s Criteria
If (Forms!Search_frm!Criteria_A is True AND
Forms!Search_frm!Criteria_B is True) Then
allRecords = CurrentDb.OpenRecordset(“qry_All_Documentsâ€, dbOpenDynaset)
End If
If (Forms!Search_frm!Criteria_A is False AND
Forms!Search_frm!Criteria_B is True) Then
allRecords = CurrentDb.OpenRecordset(“qry_Btype_Documentsâ€, dbOpenDynaset)
End If
‘Set Search_subform equal to allRecords
Set Forms!Search_frm!Search_subform.Form.RecordSource = allRecords
‘Shut down connection and recordset
allRecords.Close
Set allRecords = Nothing
Set trs = Nothing
Exit_Search_Click:
Exit Function
Err_Search_Click:
MsgBox Err.Description
Resume Exit_Search_Click
End Function