Referencing Control not on form

E

Eddy

How do I reference a control (textbox) that is in the query underlying the
form but not placed on the form itself. I am writing code behind the form
and want to place a value in the field. Do I have to place the field on
the form and just make it not visible?

Thanks.
 
S

Sandra Daigle

In Access 2000 or above you can refer to any field using the Fields
collection of the Recordset:

For example:

MsgBox Me.Recordset.Fields("Orderid")

This will also work unless there is a control named Orderid which is unbound
or bound to something else (granted that this is probably a bad idea :)).
In which case it will give you the value of the control instead:

MsgBox Me!Orderid

When possible, I prefer the first synatax since it is clear to me or anyone
else that I am going for the value from the recordset, not the control (if
one exists).
 
S

Sandra Daigle

I think I deleted a line from my original post - it should have said that in
all versions including Access97 you can use

Me!orderid

This works unless there is a control named Orderid which is unbound or bound
to something else (granted that this is probably a bad idea). In which case
it will give you the value of the control instead:

Sorry for the confusing wording :)
 

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