G
Guest
Hi All,
About a year ago, I found a FROM - WHERE code here to build a search in a
continuous form. It worked great with many "Where" criteria but now that I
added a field that affects the full database, it acts strange.
Below is the code
Private Sub Kommandoknapp30_Click()
Dim strSql As String
Dim lngLen As Long
Const strcStub = "SELECT Doctorsearchquery.ID, Doctorsearchquery.Note,
Doctorsearchquery.Quicknote, Doctorsearchquery.Country.Country AS Uttryck1,
[Doctorsearchquery].[Country.Country] AS Uttryck2, Doctorsearchquery.Region,
Doctorsearchquery.[First name], Doctorsearchquery.[Last name],
Doctorsearchquery.[Name Practice/Hospital], Doctorsearchquery.[Male/Female],
Doctorsearchquery.[Language ID], Doctorsearchquery.Phonenumber,
Doctorsearchquery.Faxnumber, Doctorsearchquery.[E-mail address],
Doctorsearchquery.Street, Doctorsearchquery.[Postal Code + City],
Doctorsearchquery.Country, Doctorsearchquery.specialisme2,
Doctorsearchquery.Speciality.Speciality,
Doctorsearchquery.Speciality_1.Speciality FROM Doctorsearchquery"
'Build the WHERE clause from the non-Null boxes.
If Not IsNull(Me.Kombinationsruta58) Then
strSql = strSql & "([Doctorsearchquery].[Country].[Country] Like
""" & Me.Kombinationsruta58 & """) AND "
End If
If Not IsNull(Me.Text50) Then
strSql = strSql & "(Doctorsearchquery.Speciality.Speciality Like
""" & Me.Text50 & "*"") OR "
End If
If Not IsNull(Me.Text50) Then
strSql = strSql & "(Doctorsearchquery.Speciality_1.Speciality Like
""" & Me.Text50 & "*"") AND "
End If
'etc for other text boxes.
lngLen = Len(strSql) - 5 'Chop off the trailiing " AND ".
If lngLen > 0 Then
strSql = strcStub & " WHERE " & Left$(strSql, lngLen) & ";"
Else
strSql = strcStub & ";"
MsgBox "No criteria"
End If
'Finally, show the search results in this form.
Me.RecordSource = strSql
End Sub
I used to only have Doctorsearchquery.Speciality.Speciality and added
Doctorsearchquery.Speciality_1.Speciality.
When I do a search and select a country in Me.Kombinationsruta58 and a
speciality in Me.Text50, it gives me results with more than one country. I
don't understand.
Anyone that has an idea?
Thanks
PS: I know it's a mess.
About a year ago, I found a FROM - WHERE code here to build a search in a
continuous form. It worked great with many "Where" criteria but now that I
added a field that affects the full database, it acts strange.
Below is the code
Private Sub Kommandoknapp30_Click()
Dim strSql As String
Dim lngLen As Long
Const strcStub = "SELECT Doctorsearchquery.ID, Doctorsearchquery.Note,
Doctorsearchquery.Quicknote, Doctorsearchquery.Country.Country AS Uttryck1,
[Doctorsearchquery].[Country.Country] AS Uttryck2, Doctorsearchquery.Region,
Doctorsearchquery.[First name], Doctorsearchquery.[Last name],
Doctorsearchquery.[Name Practice/Hospital], Doctorsearchquery.[Male/Female],
Doctorsearchquery.[Language ID], Doctorsearchquery.Phonenumber,
Doctorsearchquery.Faxnumber, Doctorsearchquery.[E-mail address],
Doctorsearchquery.Street, Doctorsearchquery.[Postal Code + City],
Doctorsearchquery.Country, Doctorsearchquery.specialisme2,
Doctorsearchquery.Speciality.Speciality,
Doctorsearchquery.Speciality_1.Speciality FROM Doctorsearchquery"
'Build the WHERE clause from the non-Null boxes.
If Not IsNull(Me.Kombinationsruta58) Then
strSql = strSql & "([Doctorsearchquery].[Country].[Country] Like
""" & Me.Kombinationsruta58 & """) AND "
End If
If Not IsNull(Me.Text50) Then
strSql = strSql & "(Doctorsearchquery.Speciality.Speciality Like
""" & Me.Text50 & "*"") OR "
End If
If Not IsNull(Me.Text50) Then
strSql = strSql & "(Doctorsearchquery.Speciality_1.Speciality Like
""" & Me.Text50 & "*"") AND "
End If
'etc for other text boxes.
lngLen = Len(strSql) - 5 'Chop off the trailiing " AND ".
If lngLen > 0 Then
strSql = strcStub & " WHERE " & Left$(strSql, lngLen) & ";"
Else
strSql = strcStub & ";"
MsgBox "No criteria"
End If
'Finally, show the search results in this form.
Me.RecordSource = strSql
End Sub
I used to only have Doctorsearchquery.Speciality.Speciality and added
Doctorsearchquery.Speciality_1.Speciality.
When I do a search and select a country in Me.Kombinationsruta58 and a
speciality in Me.Text50, it gives me results with more than one country. I
don't understand.
Anyone that has an idea?
Thanks
PS: I know it's a mess.