View Full Version : Easy one


sigmar
07-02-2001, 02:10 AM
This can't be difficult.
How can I refer to a table field in VBA to dinamically change the controlSource of a form control??

I mean changing the source to the same field, but in a different table. For example:
Changing Source from Table1.Name to Table2.Name

[This message has been edited by sigmar (edited 07-02-2001).]

Robert Saye
07-02-2001, 02:15 AM
This is from VBA help (You get VBA help by opening help from a module window).:

ControlSource Property Example

The following example sets the ControlSource property for a text box named AddressPart to a field named City:

Forms!Customers!AddressPart.ControlSource = "City"
The next example sets the ControlSource property for a text box named Expected to the expression =Date() + 7.

Me!Expected.ControlSource = "=Date() + 7"

Robert

sigmar
07-02-2001, 02:22 AM
I've already read that help, but what I want to do is refer to one of the tables in my database, not only to the field. That's because some tables have same field names.
Thanks anyway for your help.

Pat Hartman
07-02-2001, 04:31 AM
The controlsource of a field must refer to a column from the recordsource of the form if it is bound. Otherwise, it may contain a calculated value. So, you can't just re-direct the controlsource to a different table. Depending on what your objective is, you might be able to use a DLookup() function to retrieve the information or (prefered) include the other table {with a join) in the form's recordsource.