Help with SQL !! 
Author Message
 Help with SQL !!
Code:
Private Sub txtHomePhone_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
KeyAscii = 0
Dim strSQL As String
strSQL = "SELECT *From Customer Where (HomePhone = txtHomePhone)"

rsOrderInfo!LastName = txtLastName

txtLastName.SetFocus
End If
End Sub

I am Trying to find the match to a home phone number that the user enters
and show the results.I have never used SQL and would be thankful for help

Thanks
Paul

----------------



Wed, 26 Dec 2001 03:00:00 GMT
 Help with SQL !!

Paul,

I can't really make out what the code is doing, but the strSQL string should
look like this:

strSQL = "SELECT * From Customer Where (HomePhone =" & txtHomePhone & ")"

or like this if the HomePhone field is non-numeric:

strSQL = "SELECT * From Customer Where (HomePhone ='" & txtHomePhone & "')"

--
Regards

VB-Joker
Carsten Thomsen/MCSE

PLEASE post ALL replies to the newsgroup(s) so we can all benefit from the
discussion!

Quote:

> Code:
> Private Sub txtHomePhone_KeyPress(KeyAscii As Integer)
> If KeyAscii = vbKeyReturn Then
> KeyAscii = 0
> Dim strSQL As String
> strSQL = "SELECT *From Customer Where (HomePhone = txtHomePhone)"

> rsOrderInfo!LastName = txtLastName

> txtLastName.SetFocus
> End If
> End Sub

> I am Trying to find the match to a home phone number that the user enters
> and show the results.I have never used SQL and would be thankful for help

> Thanks
> Paul

> ----------------



Wed, 26 Dec 2001 03:00:00 GMT
 Help with SQL !!

Quote:

>strSQL = "SELECT *From Customer Where (HomePhone = txtHomePhone)"

This will do it:

strSQL = "SELECT * FROM Customer " & _
         "WHERE (HomePhone = """ & txtHomePhone & """);"

Hope that helps

Tim F

--



Wed, 26 Dec 2001 03:00:00 GMT
 Help with SQL !!

Quote:

> <snip>

> I am Trying to find the match to a home phone number that the user enters
> and show the results.I have never used SQL and would be thankful for help

  Listen to VB-Joker - his SQL should do the trick.
  I'm not sure why you're doing this in the TextBox KeyPress event - are
you trying to run a new query as each key is pressed?  So typing the 7
digits for a phone # will run 7 queries?  That would not be my strategy,
so maybe I'm not understanding your procedure.
  So, how are you gonna execute strSQL to select the record for the
specified phone #?  Via a DataControl, VB OpenRecordset code....?
  I've a sense you might have further questions besides the SQL syntax,
so lemme know if I can offer other info.

--
Jim in Cleveland
If you're writing to me, in my address
change "REAL_Address.see.below" to "worldnet.att.net"

"What's so funny 'bout peace, love & understanding?"
     - Nick Lowe



Wed, 26 Dec 2001 03:00:00 GMT
 Help with SQL !!
Hi Tim,

The one you suggested will not work

Quote:
> strSQL = "SELECT * FROM Customer " & _
>          "WHERE (HomePhone = """ & txtHomePhone & """);"

But this will do it

 strSQL = "SELECT * FROM Customer " & _
          "WHERE (HomePhone = "'" & txtHomePhone & "'");"

You need to use single quote for text fields.
--
Regards,
-Vijay

~~~ ~~~ ~~~ ~~~
J Vijaya Kumar Reddy

visit us at www.e-supportpoint.com


Quote:

> >strSQL = "SELECT *From Customer Where (HomePhone = txtHomePhone)"

> This will do it:

> strSQL = "SELECT * FROM Customer " & _
>          "WHERE (HomePhone = """ & txtHomePhone & """);"

> Hope that helps

> Tim F

> --




Wed, 26 Dec 2001 03:00:00 GMT
 Help with SQL !!
On Sat, 10 Jul 1999 23:42:34 +0530, "Vijay Kumar Reddy J"

Quote:

>Hi Tim,

>The one you suggested will not work

>> strSQL = "SELECT * FROM Customer " & _
>>          "WHERE (HomePhone = """ & txtHomePhone & """);"

>But this will do it

> strSQL = "SELECT * FROM Customer " & _
>          "WHERE (HomePhone = "'" & txtHomePhone & "'");"

>You need to use single quote for text fields.
>--

Incorrect. Try it.

Tim F

--



Thu, 27 Dec 2001 03:00:00 GMT
 Help with SQL !!
Jim,

I do this quite a lot in a keypress (or change) event--but with "like" instead
of "="--and put the results in a listbox, so the user can look down the
listbox, and click on the appropriate line.  Is that a good use?

Allen J. Bennett

Quote:


> > <snip>

> > I am Trying to find the match to a home phone number that the user enters
> > and show the results.I have never used SQL and would be thankful for help

>   Listen to VB-Joker - his SQL should do the trick.
>   I'm not sure why you're doing this in the TextBox KeyPress event - are
> you trying to run a new query as each key is pressed?  So typing the 7
> digits for a phone # will run 7 queries?  That would not be my strategy,
> so maybe I'm not understanding your procedure.
>   So, how are you gonna execute strSQL to select the record for the
> specified phone #?  Via a DataControl, VB OpenRecordset code....?
>   I've a sense you might have further questions besides the SQL syntax,
> so lemme know if I can offer other info.

> --
> Jim in Cleveland
> If you're writing to me, in my address
> change "REAL_Address.see.below" to "worldnet.att.net"

> "What's so funny 'bout peace, love & understanding?"
>      - Nick Lowe



Thu, 27 Dec 2001 03:00:00 GMT
 Help with SQL !!
Hi, try this:

strSQL = "SELECT * From Customer Where  HomePhone = '" & txtHomePhone & "'"

note the single quotes before and after txtHomePhone included in the
preceding and trailing substrings.

Hope it helps you
greetings

Percy

Quote:

> Code:
> Private Sub txtHomePhone_KeyPress(KeyAscii As Integer)
> If KeyAscii = vbKeyReturn Then
> KeyAscii = 0
> Dim strSQL As String
> strSQL = "SELECT *From Customer Where (HomePhone = txtHomePhone)"

> rsOrderInfo!LastName = txtLastName

> txtLastName.SetFocus
> End If
> End Sub

> I am Trying to find the match to a home phone number that the user enters
> and show the results.I have never used SQL and would be thankful for help

> Thanks
> Paul

> ----------------



Wed, 09 Jan 2002 03:00:00 GMT
 
 [ 8 post ] 

 Relevant Pages 

1. Help: Help: Help SQL Server Login Dialog appears!!!!!!!

2. Help..Help..Help MS SQL and Delphi

3. Help - Help on SQL

4. HELP HELP sql/access97/linked tables/queries

5. Please help: Basic help on SQL 6.5 need

6. Help Help SQL 7.0

7. HELP / HELP / syntax SQL / 'LIKE' clause

8. HELP! Newbie needs help with SQL for VB3

9. HELP HELP - SQL Event alerter

10. HELP --- HELP (SQL)

11. Help!!!Enumerating SQL servers in domain not using SQL-DMO

12. SQL Help on SQL Server 2000


 
Powered by phpBB® Forum Software