Is it possible to access query value in VBA?

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