Click to See Complete Forum and Search --> : SQL Question


vincentn
November 20th, 1999, 12:32 AM
I am writing a program using a MS Office Database and a visual basics program to run it. What I am trying to do is to have the students write in the name of a student that they want, and have the program post the E mail name for that student. The name of the database is "student" the field that I am searching is called "Name", and the code that I am trying to use looks like:

Data1.RecordSource = "Select * from students where Name = txtname.text "
Data1.Refresh

txtname.text is the text box where I want the students to write the name of the student that they are looking for. If you can help it would be greatly appriciated. Thanks.

November 20th, 1999, 07:33 AM
Replace with this:

Data1.RecordSource = "Select * from students where Name = " & txtname.text



Vlad

November 20th, 1999, 08:05 AM
If it's a text field, you'll likely have to enclose the field value with single quotes:


Data1.RecordSource = "Select * from students where Name = '" & txtname.text & "'"




Good luck,

Mike

santulan
November 20th, 1999, 09:01 AM
Hi,
Change the statement -
"Select * from students where Name = txtname.text "
to

"Select * from students where Name = '" & txtname.text & "'"





good luck :-)

Santulan

vincentn
November 20th, 1999, 10:28 AM
Thanks for the help, it worked great!

Gary Grant
November 22nd, 1999, 02:32 PM
If you are going to do it this way, you should be aware that names with an apostrophe in them like O'hara will cause a runtime error (the single apostrophe tells the database that you have ended the text field). Move the text to a VB string and then replace all instances of apostrophe with two apostrophe. This will tell the SQL engine that you are selecting/updating/inserting/deleting a text object with an single apostrophe.