businesshippieRH
Registered User.
- Local time
- Today, 09:48
- Joined
- Aug 8, 2014
- Messages
- 60
I have a form (frm_REVFinder) with multiple unbound comboboxes. All of the comboboxes have a row source located in tbl_Records. I am trying to filter a subform (subfrm_REVSelector) using these comboboxes.
I've been trying to get this set up and have the SQL pass-through working. However, I can't seem to get the subform's recordset to work with my pass-through strings.
When I try to run it, I get a Run-time error 2467 "The expression you entered refers to an object that is closed or doesn't exist." On the line with red font. Any help would be much appreciated! My Code:
I've been trying to get this set up and have the SQL pass-through working. However, I can't seem to get the subform's recordset to work with my pass-through strings.
When I try to run it, I get a Run-time error 2467 "The expression you entered refers to an object that is closed or doesn't exist." On the line with red font. Any help would be much appreciated! My Code:
Code:
Option Compare Database
Private Function GetWhere() As String
Dim strTemp As String
'Set Null Arguments for each criteria (Added to SQL WHERE clause "on the fly")
If Not IsNull(Me!cmb_RecordName) Then
strTemp = strTemp & " AND tbl_Records.RecordName = " & Chr(34) & Me!cmb_RecordName & Chr(34)
End If
If Not IsNull(Me!cmb_RecordDistinction) Then
strTemp = strTemp & " AND tbl_Records.RecordDistinction = " & Chr(34) & Me!cmb_RecordDistinction & Chr(34)
End If
If Not IsNull(Me!cmb_Title) Then
strTemp = strTemp & " AND tbl_Records.Title = " & Chr(34) & Me!cmb_Title & Chr(34)
End If
If Not IsNull(Me!cmb_Author) Then
strTemp = strTemp & " AND tbl_Records.Author = " & Chr(34) & Me!cmb_Author & Chr(34)
End If
If Not IsNull(Me!cmb_ProjectManager) Then
strTemp = strTemp & " AND tbl_Records.ProjectManager = " & Chr(34) & Me!cmb_ProjectManager & Chr(34)
End If
If Not IsNull(Me!cmb_SiteName) Then
strTemp = strTemp & " AND tbl_Records.[Site Name] = " & Chr(34) & Me!cmb_SiteName & Chr(34)
End If
If Not IsNull(Me!cmb_ChargeCode) Then
strTemp = strTemp & " AND tbl_Records.ChargeCode = " & Chr(34) & Me!cmb_ChargeCode & Chr(34)
End If
If Not IsNull(Me!cmb_ContractNumber) Then
strTemp = strTemp & " AND tbl_Records.PrimeContractNumber = " & Chr(34) & Me!cmb_ContractNumber & Chr(34)
End If
If Not IsNull(Me!cmb_TaskOrder) Then
strTemp = strTemp & " AND tbl_Records.TaskOrder = " & Chr(34) & Me!cmb_TaskOrder & Chr(34)
End If
'Set string to add
strTemp = Mid(strTemp, 6)
'Make sure not all null
If Len(strTemp) > 0 Then
GetWhere = "Where" & strTemp
End If
End Function
Private Sub btn_Search_Click()
Dim strSQL As String
strSQL = "SELECT tbl_Records.RecordName, tbl_Records.RecordDistinction, tbl_Records.Title, tbl_Records.Author, " & _
"tbl_Records.ProjectManager, tbl_Records.[Site Name], tbl_Records.ChargeCode, tbl_Records.PrimeContractNumber, " & _
"tbl_Records.TaskOrder, tbl_Records.RecordDateMONTH, tbl_Records.RecordDateYEAR, " & _
"FROM tbl_Records;"
Dim Finder As String
Finder = strSQL & GetWhere()
'Set subform equal to results of query
[COLOR="Red"]Me.subfrm_REVSelector.Form.RecordSource = Finder[/COLOR]
End Sub