shyamsundar
Programmer
Hi techies,
This is what i tried to search records on a table
****************************************
Private Sub cmdKYGO_Click()
Dim row As Integer
Dim strKWQUERY As String
row = lstCOUNTRY.ListIndex
If row < 0 Then
MsgBox "Please Select Country"
lstCOUNTRY.SetFocus
Exit Sub
ElseIf txtSEARCH.Value = "Enter Search String" Then
MsgBox "Please type your Search String"
txtSEARCH.SetFocus
Exit Sub
End If
Dim strSRCH As String
strSRCH = txtSEARCH.Value
Dim dbHIV As Database
Dim qdfKWSRCH As QueryDef
Set dbHIV = CurrentDb
strKWQUERY = "select * from 1a where [1a.8] like '*" & strSRCH & "*'" _
& " or [1a.11] like '*" & strSRCH & "*'" _
& " or [1a.13] like '*" & strSRCH & "*'" _
& " or [1a.44] like '*" & strSRCH & "*'" _
& " or [1a.46] like '*" & strSRCH & "*'" _
& " order by [1a.1]"
For Each qdfKWSRCH In dbHIV.QueryDefs
If qdfKWSRCH.Name = "KW_SRCH" Then
DoCmd.DeleteObject acQuery, "KW_SRCH"
End If
Next qdfKWSRCH
Set qdfKWSRCH = dbHIV.CreateQueryDef("KW_SRCH", strKWQUERY)
dbHIV.QueryDefs.Refresh
DoCmd.OpenForm "KW_SRCH", acNormal
End Sub
***********************************************
Now, the problem is, the user enters more than one word seperated by comma(, this can be changed to +) to search, the above code will not search as it is looking for the string (SUGAR,MILK) AND NOT SUGAR & MILK seperately. Please any help.
Shyam
Shyam
cwizshyam@yahoo.com
This is what i tried to search records on a table
****************************************
Private Sub cmdKYGO_Click()
Dim row As Integer
Dim strKWQUERY As String
row = lstCOUNTRY.ListIndex
If row < 0 Then
MsgBox "Please Select Country"
lstCOUNTRY.SetFocus
Exit Sub
ElseIf txtSEARCH.Value = "Enter Search String" Then
MsgBox "Please type your Search String"
txtSEARCH.SetFocus
Exit Sub
End If
Dim strSRCH As String
strSRCH = txtSEARCH.Value
Dim dbHIV As Database
Dim qdfKWSRCH As QueryDef
Set dbHIV = CurrentDb
strKWQUERY = "select * from 1a where [1a.8] like '*" & strSRCH & "*'" _
& " or [1a.11] like '*" & strSRCH & "*'" _
& " or [1a.13] like '*" & strSRCH & "*'" _
& " or [1a.44] like '*" & strSRCH & "*'" _
& " or [1a.46] like '*" & strSRCH & "*'" _
& " order by [1a.1]"
For Each qdfKWSRCH In dbHIV.QueryDefs
If qdfKWSRCH.Name = "KW_SRCH" Then
DoCmd.DeleteObject acQuery, "KW_SRCH"
End If
Next qdfKWSRCH
Set qdfKWSRCH = dbHIV.CreateQueryDef("KW_SRCH", strKWQUERY)
dbHIV.QueryDefs.Refresh
DoCmd.OpenForm "KW_SRCH", acNormal
End Sub
***********************************************
Now, the problem is, the user enters more than one word seperated by comma(, this can be changed to +) to search, the above code will not search as it is looking for the string (SUGAR,MILK) AND NOT SUGAR & MILK seperately. Please any help.
Shyam
Shyam
cwizshyam@yahoo.com