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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rst for query statement rather than table

Status
Not open for further replies.

Darrylles

Programmer
Feb 7, 2002
1,758
GB
Hi,

I can use this:

Set rst = CurrentDb.OpenRecordset("mytable", dbOpenDynaset)

and manipulate records within 'mytable' no problem.

How can I say:

Set rst = CurrentDb.OpenRecordset(mySQLString, dbOpenDynaset)

and do the same?

i.e. How can I set rst to = a SQL query result (from current db). I'm going to have to do this via a hidden form - which I don't want to do 'cos it's really naff.

p.s. I've already posted a problem regarding defining as 'database' (Access 2000) so I can't use: 'dim db as database' at this moment - lol.

All help appreciated.

Regards,

Darrylle


"Never argue with an idiot, he'll bring you down to his level - then beat you with experience." darrylles@totalise.co.uk
 
Hi,

Best way is define a string variable (Dim MySqlString as string).

Then assign the SQL statement to it.

e.g. MySqlStr = "Select * from mytable;"

Don't forget the required SQL semi-colon terminator.

Then....

Set rst = CurrentDb.OpenRecordset(MySqlStr, dbOpenDynaset)

You can always do this however:

Set rst = CurrentDb.OpenRecordset("Select * from mytable;", dbOpenDynaset)

Both are identical to the compiler.

Regards,

Darrylle


"Never argue with an idiot, he'll bring you down to his level - then beat you with experience." darrylles@totalise.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top