What can i do with OpenRecordset

P

Paul

I want to have a query in VBA and after to open it.
i tried with OpenRecordset but doesn't work
 
S

SA

Paul:

It sounds like you want to open the recordset in the query designer?

OpenRecordset, opens a result set of a query or SQL statement in memory,
where you can read or write (dependent on how it is opened,) against the
data in the recordset and database in general.

If you've successfully created a query definition and set its SQL and want
to open it in the user interface in the query designer, then you use a
different statement i.e. DoCmd.OpenQuery

If I've missed your point, then please supply more information and repost.
 
P

Paul

Yes right i want to create a query definition in VBa and
after to open it like i open when i create it in design
wiev.
I mean i don't want to have a lot of query in the query
window,but i want to create query with code and after to
open them
I tried with this but doesn't work
Sub a()
Dim SQL As String
SQL = "SELECT Categories.Price FROM Categories;"
DoCmd.OpenQuery "SQL", , acReadOnly

End Sub
 
H

Hafeez Esmail

Looks like you want to Createa query definintion
(CreateQueryDef).

dim qdfMyQry as QueryDef
set qdfMyQry = dbs.CreateQueryDef( NameOfQuery, SQL)

HTH

Hafeez Esmail
 

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