|
-
Aug 7th, 1999, 09:50 PM
#1
Thread Starter
Lively Member
Private Sub Find_Click()
Dim var As String
var = varHomePhone
With Me.Data1.Recordset
.FindFirst "HomePhone='" & var & "'"
If .NoMatch Then
MsgBox " You Must first add this customer"
AddCust.Show vbModal
End If
End With
End Sub
Can any one give me the code to do this in SQL?
Thanks
Paul
-
Aug 8th, 1999, 12:27 AM
#2
Frenzied Member
[not tested]
Dim DB as database
dim rs as recordset
Set db = workspaces(0).Opendatabase("dbname")
set rs = db.openrecordset ("select * from tablename where HomePhone='" & varHomePhone & "'", dbopensnapshot)
if rs.eof = true then
MsgBox " You Must first add this customer"
AddCust.Show vbModal
end if
-
Aug 8th, 1999, 03:06 AM
#3
Member
Get in the habit of using chr(34) in place of single or double quote characters around the criteria.
"SELECT * FROM tbl WHERE tbl.Fld = " & chr(34) & x & chr(34)
Will allow you to save and then search for strings that have embedded quotes (users want to hold names like "O'Brien"? now you can) and make building string variables easier.
-robert
-
Aug 8th, 1999, 04:22 AM
#4
Frenzied Member
Better yet, assign a constant to contain the value:
QUOTE = chr(34)
"SELECT * FROM tbl WHERE tbl.Fld = " & QUOTE & x & QUOTE
Cost you next to nothing and is infintely more readable.
-
Aug 9th, 1999, 05:07 PM
#5
New Member
Even easier is to just use "double double-quotes" (wow!)
Eg. mystring = "Here is a quote ("") for you."
? mystring would show:
Here is a quote(") for you.
So: you can use it in SQL like this
strSQL = "SELECT * FROM myTable WHERE mystring = """ & strCheckString & """ AND... etc
Notice the THREE quotes after mystring =... - the third ends the first bit of the string - looks a bit strange but you soon get used to it and don't have to remember to declare a quote character or the ascii no of the quote character.
Hope it helps!
------------------
Chris Keeble
www.giglist.com
mailto:[email protected]
-
Aug 9th, 1999, 08:44 PM
#6
Frenzied Member
I've been known to do it all 3 ways. Which one I use depends on, 1) how much time I have, 2) the last place I applied SQL code (I work on MVS DB/2, SQL Server 6.5 [just starting 7.0], and Access and 3) how permanent the code is going to be, for me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|