Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search code not working

Status
Not open for further replies.
Sep 16, 2005
191
US
Hi, I am not an expert in Access and I am working on an access database now but got stuck. I have a code for my search command but it does not seem to work. How do I troubleshoot it.. Here is the problem: When I type the partial UserID, it does nothing.It didn't give me my message. But when I enter the full UserID, it searchs.. Also, When I type in the full A_First_Name and search, it does nothing also. Any suggestion?

Here is my code

Private Sub cmdSearch_Click()
On Error GoTo Err_cmdSearch_Click

Dim xflag As Boolean, sWhere As String, sSQLstring As String
Dim cnn As ADODB.Connection, test As Integer

Dim db As DAO.Database, rs As DAO.Recordset 'use this to do recordcount only
Set db = CurrentDb 'use this to do recordcount only

Set cnn = CurrentProject.Connection

Dim rst As New ADODB.Recordset


xflag = False

If Not IsNull(Me!A_UserID) Then

xflag = True

If Len(sWhere) > 0 Then sWhere = sWhere & " and "

sWhere = sWhere & "Attendee.A_UserID like '*" & Me!A_UserID & "*'"
End If

If Not IsNull(Me!A_First_Name) Then
xflag = True

If Len(sWhere) > 0 Then sWhere = sWhere & " and "

sWhere = sWhere & "Attendee.A_First_Name Like '*" & Me!A_First_Name & "*'"
End If

If Not IsNull(Me!A_Last_Name) Then
xflag = True

If Len(sWhere) > 0 Then sWhere = sWhere & " and "

sWhere = sWhere & "Attendee.A_Last_Name Like '*" & Me!A_Last_Name & "*'"
End If


If xflag Then sWhere = " WHERE (" & sWhere & ")"

sSQLstring = "select * from Attendee "

sSQLstring = sSQLstring & sWhere

Set rs = db.OpenRecordset(sSQLstring)

If Not rs.EOF Then rs.MoveLast

If rs.RecordCount = 0 Then
MsgBox "There is no record that matches your criteria, please check your data again.", vbInformation, "PMC Database"
Me.SearchResultSub.Form.RecordSource = sSQLstring
Me.SearchResultSub.Requery
GoTo Exit_cmdSearch_Click:
End If

'Set rst = Nothing

'rst.Open sSQLstring, cnn, adOpenKeyset, adLockOptimistic

'If Not rst.EOF Then rst.MoveLast

Me.SearchResultSub.Form.RecordSource = sSQLstring
Me.SearchResultSub.Requery


'rst.Close
'cnn.Close
rs.Close
db.Close

Exit_cmdSearch_Click:

Exit Sub

Err_cmdSearch_Click:
If Err = 3021 Then Resume Next
MsgBox Err.Description
Resume Exit_cmdSearch_Click
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top