SQL\VB Script and Access

C

chia

I am new to SQL and VB Script but I need to get data from a database
that I have been given.
I have maneged to use the INSERT commands to put data in and the SELECT
commands in a query. The problem is that I cant work out how to get the
query result which is a sinlge number back into VBScript.

I have
sql = "SELECT ID FROM Summary WHERE ID = '111a'"
DB.Execute sql

This works and I know the answer is 1. What commadn should go after DB.
to get the answer?
 
R

Rick Brandt

chia said:
I am new to SQL and VB Script but I need to get data from a database
that I have been given.
I have maneged to use the INSERT commands to put data in and the SELECT
commands in a query. The problem is that I cant work out how to get the
query result which is a sinlge number back into VBScript.

I have
sql = "SELECT ID FROM Summary WHERE ID = '111a'"
DB.Execute sql

This works and I know the answer is 1. What commadn should go after DB.
to get the answer?

You don't execute a SELECT query. That is only for action queries. To do
what you want you have to create a RecordSet that uses the SQL for your
SELECT query and then you can pull values out of the RecordSet.

Dim rs as DAO.Recordset
sql = "SELECT ID FROM Summary WHERE ID = '111a'"
Set rs = DB.OpenRecordset(sql)
If Not rs.EOF Then SomeVariable = rs!ID
rs.Close
Set rs = Nothing
blah blah...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top