Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running SQL from Access VB

Status
Not open for further replies.

DoDo1975

Technical User
Jun 4, 2002
18
CA
I have a search form which creates a valid SQL statement from the form elements. I have verified that SQL is correct by pasting into a query and running.

I would like to use this SQL string I have created to allow users to press a button on the access form, which will then run the query against the database and return all the records for it. The statement includes up to 4 tables in the SELECT and FROM clauses and only one statement in the WHERE clause.

What commands or methods of what objects do I use to open up a recordset using this SQL statement.

Example code would be much appreciated.

Thanks in advance.

JL
 
The code would be something like:

Dim db as database
dim rs as recordset
dim sqlstr as string

sqlstr = your sql statement

set db = currentdb
set rs = db.openrecordset sqlstr

However, the SQL statement as it appears in the SQL view of the query may not work here.

Check the help file under:
Build SQL Statements That Include Variables and Controls
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top