Query Access Database

Rebel7

Registered User.
Local time
Today, 04:00
Joined
Feb 17, 2009
Messages
23
Hi Guys,

I am trying to figure out how to query an access database table called Phone Numbers from a webpage.

Basically I have textbox (called phn) and a search button (called submit). The value entered in the textbox is queried to the table and if found a msgbox pops up saying "Found" and if not found the message box pops up saying "Not Found."

I have gotten so far as this but I am stuck and can't figure it out:

connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\PhoneNumbers.mdb

sql = "select * from Number.Phone where Number = phn.text"

set cn = createobject("ADODB.Connection")
set cmd = createobject("ADODB.Command")

cn.open connectionString

cmd.ActiveConnection = cn

cmd.CommandText = sql

set rs = cmd.execute

Any help would be appreciated.
 
Try:

sql = "SELECT * FROM Phone WHERE (((Number =" & phn.text & "));"

You can't use both the table name and field name after the FROM clause as you show, only use the table name ------- "Number.Phone" which I have assumed is "Phone"

I'm not sure "Number" is a good choice as it is probably a reserved word and may cause strange errors.
 
Thanks Gizmo,

I made the changes, but the problem is still there. I believe that my code isn't complete or I am missing some important scripts that need to be there for the query to work. I don't know.
 
That's the correct syntax (90% sure) for MS Access, but it could possibly be wrong from VB.
 

Users who are viewing this thread

Back
Top Bottom