Is it possible to access query value in VBA?

E

EdAROC

I was wondering if it's possible to reference a query value, in the same way
values can be retrieved from other objects, such as:
Forms!frm123!txtABC

The specific case is, the {...} is the referencing I want:
Detail.BackColor = {Query!qryReportData!Backcolor}

Background: The standard technique is to create a (hidden) textbox and
reference that. I'm just optimizing. Impact to the user? If there's someone
out there who can react in milliseconds it will save them milliseconds,
otherwise, no benefit, just my own satisfaction.
 
F

fredg

I was wondering if it's possible to reference a query value, in the same way
values can be retrieved from other objects, such as:
Forms!frm123!txtABC

No, you cannot reference data in a query this way.
The specific case is, the {...} is the referencing I want:
Detail.BackColor = {Query!qryReportData!Backcolor}

Background: The standard technique is to create a (hidden) textbox and
reference that. I'm just optimizing. Impact to the user? If there's someone
out there who can react in milliseconds it will save them milliseconds,
otherwise, no benefit, just my own satisfaction.

If the query returns just one record, use:
DLookUp("[FieldName]","QueryName")

Change the field and query names as needed.

If the query returns more than one record, you will need to add a
where clause to the above in order to get the correct record's value.

Look up DLookUp in VBA help, as well as
Restrict data to a subset of records
 
F

fredg

I was wondering if it's possible to reference a query value, in the same way
values can be retrieved from other objects, such as:
Forms!frm123!txtABC

No, you cannot reference data in a query this way.
The specific case is, the {...} is the referencing I want:
Detail.BackColor = {Query!qryReportData!Backcolor}

Background: The standard technique is to create a (hidden) textbox and
reference that. I'm just optimizing. Impact to the user? If there's someone
out there who can react in milliseconds it will save them milliseconds,
otherwise, no benefit, just my own satisfaction.

If the query returns just one record, use:
DLookUp("[FieldName]","QueryName")

Change the field and query names as needed.

If the query returns more than one record, you will need to add a
where clause to the above in order to get the correct record's value.

Look up DLookUp in VBA help, as well as
Restrict data to a subset of records
 
E

EdAROC

Rats!
Multiple records will be returned, since this is a recordset for a report
reducing the number of records to 1 is not going to work.

Thanks for the information.
 
E

EdAROC

Rats!
Multiple records will be returned, since this is a recordset for a report
reducing the number of records to 1 is not going to work.

Thanks for the information.
 

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