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

In Access, How set object to SQL Select Statement

Status
Not open for further replies.

tomcone

Technical User
Apr 22, 2004
4
US
I want to have an On Change event which sets an unbound field in the subform to be the equal to the result of a SQL Select query. What is the VBA code to say:

UnboundCntrol= Select .. from ... where ...;

I keep getting compile errors on my attempts.

Thx
 
Not overly familar with this but I would suggest that you need to set the SQL as a string and then reference the RECORDSET returned by it

Rgds, Geoff

Never test the depth of water with both feet

Help us to help you by reading FAQ222-2244 before you ask a question
 
I believe that the DLookup Function is what you are looking for.

UnboundControl = DLookup("FieldName", "TableName", "Criteria")
 
Hi tomcone,

mndrlion is right. DLookup is almost certainly what you're after. You should not, however, normally need to set it in code. If you set the Control's Control Source Property to it that ought to be sufficient

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top