Recordset SQL MSAccess question rather confused? *RESOLVED*
I have a search/find dialog box that pops up when the client/user wants to search the records in the membership table in the database. the client/user can search by member id, home phone, last name, and driver license. the client/user can type in part of a search value followed by an asterisk "*". the value is passed to a function and a SQL statement is created using a LIKE search. This is being performed on an access database. I can get the query to work from within access using the query design view. however, i cannot get the SQL statement to work from within my program when i open a recordset with it. it doesn't fail but it does not return any records. i hope this make sense. here is the SQL statement that i create the SQL is then passed to a class function. any help will be greatly appreciated. thanks in advance.
VB Code:
Public Function FindMember(ByVal sSearchVal As String, ByVal sField As String) As Long
Dim sSQL As String
Dim lCnt As Long
'Determine if the recordset has been created.
If rs Is Nothing Then
Set rs = New ADODB.Recordset
End If
'Determine if the recordset has been opened.
If rs.State = adStateOpen Then
rs.Close
End If
'Determine if the value being searched for has an astrics
'in the string.
If InStr(sSearchVal, "*") Then
'If there is an astrics perform a SQL LIKE query.
sSQL = "SELECT * FROM members WHERE " & sField & " LIKE '" & UCase(sSearchVal) & "'"
Else
'If there is no astrics perform a normal SQL SELECT query.
sSQL = "SELECT * FROM members WHERE " & sField & " = '" & UCase(sSearchVal) & "'"
End If
'Get the member data based on the SQL statement.
Call GetMemberData(sSQL)
'Get the number of records found if any.
lCnt = cDB.RecCount(rs)
If lCnt <= 1 Then
'If the record count is 1 or less there is no need to use
'the mover buttons.
Call DisEnableMemMoverButtons(False, False, False, False, frmMembers)
Else
'More then 1 record enable all mover buttons.
Call DisEnableMemMoverButtons(True, True, True, True, frmMembers)
End If
FindMember = lCnt
End Function
Re: Recordset SQL MSAccess question rather confused?
Quote:
Originally posted by Virus00110
VB Code:
If InStr(sSearchVal, "*") Then
'If there is an astrics perform a SQL LIKE query.
sSQL = "SELECT * FROM members WHERE " & sField & " LIKE '" & UCase(sSearchVal) & "'"
Else
'If there is no astrics perform a normal SQL SELECT query.
sSQL = "SELECT * FROM members WHERE " & sField & " = '" & UCase(sSearchVal) & "'"
End If
My first question is:
Does Instr(sSearchVal,"*") return anything??
If yes, then this might be the solution:
In the first sql where u use Like, try the following sql statement:
sSQL = "SELECT * FROM members WHERE " & sField & " LIKE '%" & UCase(sSearchVal) & "%'"
Let me know if it works!!!!
Enjoy!!!
apps_tech