Results 1 to 5 of 5

Thread: help with sql statement

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    help with sql statement

    hi all
    I have been runing into a wall trying to get this statement to work
    I want to be able to search DB by either Address or by the customers name.
    The address search works due to help from dee-u and I can get the search for a name to work except I can't pass the SQL statement the customers whole name ie: John Smith. It will work if I change sql to LastName or FirstName . then by entering either there first or last name the search will work.
    I know it's just that I don't have the sql statement right. to search both FirstName and LastName fields but I can't seem to build a correct statement.
    any help
    bty Thanks dee-u for the help allready

    VB Code:
    1. Private Sub cmdSearch_Click()
    2. Dim Address As String
    3. Dim LastName As String
    4. Dim FirstName As String
    5.  
    6.     If Len(Trim$(txtSearchBox)) = 0 Then
    7.         MsgBox "Please input a value"
    8.         txtSeachbox.SetFocus
    9.         Exit Sub
    10.     End If
    11.  
    12.     If Option1 = True Then
    13.         Address = Trim$(txtSearchBox)
    14.         frmCustomers.datPrimaryRS.Recordset.MoveFirst
    15.         frmCustomers.datPrimaryRS.Recordset.Find "Address = '" & Address & "'"
    16.     End If
    17.     If Option2 = True Then
    18.         FirstName = Trim$(txtSearchBox)
    19.         LastName = Trim$(txtSearchBox)
    20.         frmCustomers.datPrimaryRS.Recordset.MoveFirst
    21.         frmCustomers.datPrimaryRS.Recordset.Find "FirstName = '" & FirstName & "'" And "LastName = '" & LastName & "'"
    22.     End If
    23.    
    24. Unload Me
    25. End Sub

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: help with sql statement

    The Find property only allows you to use one criteria, instead try using the Filter property instead:


    VB Code:
    1. rs.Filter "FirstName = '" & FirstName & "'" And "LastName = '" & _  
    2. LastName & "'"

    See this post
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    Re: help with sql statement

    ok I agree

    but this
    VB Code:
    1. frmCustomers.datPrimaryRS.Recordset.Filter "FirstName = '" & FirstName & "'" And "LastName = '" & _
    2. LastName & "'"
    creates a invalid use of property error

  4. #4
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: help with sql statement

    Quote Originally Posted by crater
    ok I agree

    but this
    VB Code:
    1. frmCustomers.datPrimaryRS.Recordset.Filter "FirstName = '" & FirstName & "'" And "LastName = '" & _
    2. LastName & "'"
    creates a invalid use of property error

    Try this instead:

    VB Code:
    1. [B]datPrimaryRS.Filter[/B] "FirstName = '" & FirstName & "'" And "LastName = '" & _
    2. LastName & "'"
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    Re: help with sql statement

    now it's Type Mismatch

    VB Code:
    1. Private Sub cmdSearch_Click()
    2. Dim Address As String
    3. Dim LastName As String
    4. Dim FirstName As String
    5.  
    6.     If Len(Trim$(txtSearchBox)) = 0 Then
    7.         MsgBox "Please input a value"
    8.         txtSeachbox.SetFocus
    9.         Exit Sub
    10.     End If
    11.  
    12.     If Option1 = True Then
    13.         Address = Trim$(txtSearchBox)
    14.         frmCustomers.datPrimaryRS.Recordset.MoveFirst
    15.         frmCustomers.datPrimaryRS.Recordset.Find "Address = '" & Address & "'"
    16.     End If
    17.     If Option2 = True Then
    18.         FirstName = Trim$(txtSearchBox)
    19.         LastName = Trim$(txtSearchBox)
    20.         frmCustomers.datPrimaryRS.Recordset.MoveFirst
    21.         datPrimaryRS.Recordset.Filter ("FirstName = '") & FirstName & "'" And ("LastName = '") & _
    22. LastName & "'"
    23.     End If
    24.    
    25. Unload Me
    26. End Sub
    and I think I have to have the frmCustomer. beause this is a different form not a searchbox
    but when I add it with that code I get Invalid use of Property error take it away and type mismatch error
    Last edited by crater; Dec 30th, 2005 at 12:25 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width