SELECT

  • Thread starter Thread starter revbjones
  • Start date Start date
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...
 
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
 
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
 
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.
 
Back
Top