SELECT

R

revbjones

How do I write SELECT statements in VBA. I keep
getting "Need Case" Error. I want to pull fields from a
record based in entries from another field on the current
form with a different source...

Bennie...
 
D

Dan Artuso

Hi,
Do you mean you want to open up a recordset?
What do you want to do with the results?

Dim strSql AS string
Dim rs As DAO.Recordset

strSql = "Select * From yourTable Where someTextField = '" & Me.someControl & "'"
Set rs = CurrecntDb.OpenRecordset(strSql)


Then you can process the recordset any way you want.
Sometimes though, DLookup will do what you want as well.
Look it up in Help for more info.

HTH
Dan Artuso, MVP
 
R

REVBJONES

Thanks, do I put it as an event of the form or attach it
to a control on the form?
 
G

Guest

By the way, you asked what I intend to do with the
results... I want to put the value of a field from
another table in a field on my current form based on
values (2) from fields on the form that has the focus...
(current form)

Bennie
 
D

Dan Artuso

Hi,
Then it sounds like DLookup would be better for you.
To give you exact code i would need to know the name of the
two controls on the form, the name of the field in the other table
and the name of the table. Also, I need to know the data type of the two
fields that will be useed as criteria.

In the meantime, look up DLookup in help to get an idea of how it works.
 

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