Beginner question - getting the values of a query into two variables

P

PromisedOyster

I have setup a read-only Access query and that works well. This
basically returns 1 row and 2 columns from a database table.

I now want to put these two values into two seperate VB variables (for
holding parameter options).

Here is what I have done:

dim opt1 as string
dim opt2 as string

DoCmd.OpenQuery "myQuery", acNormal, acReadOnly
opt1 = DoCmd.??? ' Somehow get col1, row 1 from the query
opt1 = DoCmd.???' Somehow get col2, row 1 from the query
DoCmd.Close acQuery,"myQuery", acSaveNo

Can anyone fill in the Question marks. I assume it should be simple?
 
J

John W. Vinson

I have setup a read-only Access query and that works well. This
basically returns 1 row and 2 columns from a database table.

I now want to put these two values into two seperate VB variables (for
holding parameter options).

Here is what I have done:

dim opt1 as string
dim opt2 as string

DoCmd.OpenQuery "myQuery", acNormal, acReadOnly
opt1 = DoCmd.??? ' Somehow get col1, row 1 from the query
opt1 = DoCmd.???' Somehow get col2, row 1 from the query
DoCmd.Close acQuery,"myQuery", acSaveNo

Can anyone fill in the Question marks. I assume it should be simple?

No DoCmd is needed, nor is it necessary to open the query:

opt1 = DLookUp("col1", "MyQuery")
opt2 = DLookUp("col2", "MyQuery")

assuming that the fieldnames are actually col1 and col2.
 

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