Hi all,
I don't do this stuff much anymore but I have had a database in which I wrote a long time ago.
Anyways I wrote some vb (with the help of this site) that creates a sring and sql based on search criteria and then sets the recordset of the subform to the results.
However something strange has happened and I cannot get my head around it but it's probably very simple!
If I do:
Me.[searchSubForm].Form.RecordSource = "SELECT * FROM FindClient"
I only get the current record of the main form listed in the subform not all records that I was expecting.
So the subform only has limited access to the data? I don't understand why.
Here is the code on the search button click:
I don't do this stuff much anymore but I have had a database in which I wrote a long time ago.
Anyways I wrote some vb (with the help of this site) that creates a sring and sql based on search criteria and then sets the recordset of the subform to the results.
However something strange has happened and I cannot get my head around it but it's probably very simple!
If I do:
Me.[searchSubForm].Form.RecordSource = "SELECT * FROM FindClient"
I only get the current record of the main form listed in the subform not all records that I was expecting.
So the subform only has limited access to the data? I don't understand why.
Here is the code on the search button click:
Code:
Dim sq As String
sq = "" 'set variable
If Not IsNull(SurnameSearch) Then
sq = "WHERE FindClient.Surname LIKE ""*" & Me!SurnameSearch & "* """
End If
If Not IsNull(AddySearch) Then
sq = "WHERE FindClient.Address1 LIKE ""*" & Me!AddySearch & "*"""
End If
If Not IsNull(PostCodeSearch) Then
sq = "WHERE FindClient.Postcode LIKE ""*" & Me!PostCodeSearch & "*"""
End If
If sq <> "" Then
sq = "WHERE" & Right$(sq, Len(sq) - 5) '
sq = "SELECT * FROM FindClient " & sq ' Find records in table & Where etc (variable)
Me.[searchSubForm].Form.RecordSource = sq ' set record set based on results
Me.HelpTip1.Caption = "Search Complete!! Now Click on the corresponding grey box next to the search results!"
End If
If sq = "" Then
MsgBox "Please input a search term!!!!!", vbExclamation, "User Error!!!"
End If
If Me.[searchSubForm].Form.RecordsetClone.RecordCount = 0 Then 'if no results (very unlikley since using like *?*)
'Me.Form.RecordSource = "SELECT * FROM Findclient WHERE False;"
MsgBox "No records match the criteria you entered.", vbExclamation, "No Records Found"
sq = "SELECT * FROM FindClient" 'Select All
Me.[searchSubForm].Form.RecordSource = sq
End If
End Sub