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:
Private Sub cmdSearch_Click()
Dim Address As String
Dim LastName As String
If txtSearchBox = "" Then
MsgBox "Please input a value"
End If
If Option1 = True Then Address = txtSearchBox
frmCustomers.datPrimaryRS.Recordset.MoveFirst
frmCustomers.datPrimaryRS.Recordset.Find "Address = '" & [Address] & "'"
If Option2 = True Then FirstName = txtSearchBox
frmCustomers.datPrimaryRS.Recordset.MoveFirst
frmCustomers.datPrimaryRS.Recordset.Find "FirstName = '" & FirstName & "'"
Unload Me
End Sub
Re: problem with SQL statement
Will you try it like this?
VB Code:
Private Sub cmdSearch_Click()
Dim Address As String
Dim LastName As String
If Len(Trim$(txtSearchBox)) = 0 Then
MsgBox "Please input a value"
txtseachbox.SetFocus
Exit Sub
End If
If Option1 = True Then
Address = Trim$(txtSearchBox)
frmCustomers.datPrimaryRS.Recordset.MoveFirst
frmCustomers.datPrimaryRS.Recordset.Find "Address = '" & Address & "'"
End If
If Option2 = True Then
FirstName = Trim$(txtSearchBox)
frmCustomers.datPrimaryRS.Recordset.MoveFirst
frmCustomers.datPrimaryRS.Recordset.Find "FirstName = '" & FirstName & "'"
End If
End Sub
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:
frmCustomers.datPrimaryRS.Recordset.Find "FirstName = '" & FirstName & "'" & "LastName = '" & LastName & "'"