Using the Format Event to assign value to Unbound text box

A

Alistair F

I'm trying to use code to assign a value to an unbound text box. I need to
use values from the current record of the RecordSource but Access complains
when the report is run saying that it cannot find the field required. It is
possible to use iif the assign the value to the text box but using the format
event would be easier to maintain, I think.

Any ideas as to why coding the format procedure doesn't work?
 
M

Marshall Barton

Alistair F said:
I'm trying to use code to assign a value to an unbound text box. I need to
use values from the current record of the RecordSource but Access complains
when the report is run saying that it cannot find the field required. It is
possible to use iif the assign the value to the text box but using the format
event would be easier to maintain, I think.

Any ideas as to why coding the format procedure doesn't work?


I think you either you misspelled the field name or you do
not have a control in the report that's bound to the field.

Since an Access optimization doesn't waste time retrieving
data the is not referenced in the report's controls, there
is no point to refering to a field in the record source
table/query. Instead you can refer to the bound control and
be consistent with how you reference other values.
 
A

Alistair F

Many thanks for this. Now I understand why my code doesn't work. I'll need to
rethink the approach, though. There's no point in writing code for the format
event if I need to bind all the fields in the recordsource first, unless
there's a way of forcing Access to retrieve fields that aren't bound to
controls in the report.

Thanks again for the help.

Alistair
 
M

Marshall Barton

You do not actually have to have a separate bound control
for every field you want to refer to only in VBA procedures.
You can reference many fields in a single hidden text box
with an expression (e.g. =f1 & f2 & f3 & ...)

OTOH, there may be a more straightforward way to design your
report using normal bound fields. Depends on what you are
trying to accomplish.
 

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