Results 1 to 3 of 3

Thread: problem with SQL statement

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    problem with SQL statement

    I have this code and it works except for the Address query I think because a address has spaces in it, my statment won't work, but maybe it's somthing else.
    Also I would need to search more that just there First Name. I will need to search for First and Last Name ie: Joe Blow and/or a Address ie: 1324 N. Center st
    Once I see how the statement is made I think I can build it futher but right now I'm not that familar with SQL
    any help would be great

    VB Code:
    1. Private Sub cmdSearch_Click()
    2. Dim Address As String
    3. Dim LastName As String
    4.  
    5.     If txtSearchBox = "" Then
    6.         MsgBox "Please input a value"
    7. End If
    8.  
    9.     If Option1 = True Then Address = txtSearchBox
    10.        
    11.         frmCustomers.datPrimaryRS.Recordset.MoveFirst
    12.         frmCustomers.datPrimaryRS.Recordset.Find "Address = '" & [Address] & "'"
    13.  
    14.     If Option2 = True Then FirstName = txtSearchBox
    15.        
    16.         frmCustomers.datPrimaryRS.Recordset.MoveFirst
    17.         frmCustomers.datPrimaryRS.Recordset.Find "FirstName = '" & FirstName & "'"
    18.      
    19. Unload Me
    20. End Sub

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: problem with SQL statement

    Will you try it like this?

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


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    Re: problem with SQL statement

    Thanks dee-u
    I was Pulling my hair out over this
    I read somewhere that the [] were used to take care of spaces but I see that you used Trim to do it.

    One thing I don't understand is how the statement is built? I have read that the statement is what you would find after the Where clause in a SQL statement and that the single quote " ' " is the specify a string. Could you please explain how the statement is built or direct me to a tut that I can learn from?
    also I want to search for a name like Joe Blow something like this I think
    VB Code:
    1. frmCustomers.datPrimaryRS.Recordset.Find "FirstName = '" & FirstName & "'" & "LastName = '" & LastName & "'"
    Last edited by crater; Dec 29th, 2005 at 12:40 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