Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a field caption using VBA

Status
Not open for further replies.

CharlieT302

Instructor
Mar 17, 2005
406
US
Hi Folks,

I have a visual basic code that sets the record source for a combo box control on a form. The record source is a relational query. I need a way to also apply a caption to the fields selected by the query.

I have to do it thru VBA because the code changes the record source based upon other field values. Therefore, I cannot set the caption on a table.

thanks

 
In your query, you can set the names of the fields to anything you want. I've had to do that when showing results in a listbox control.

For example...

SELECT MyIDField As [User ID], MyNameField As [User Name]...
 
No. It has to be done in VBA.

The field displayed in the combo box are determined by values chosen in other fields. The VBA code analyzed the choice of the other field and then sets the record source for the combo box. Anything done in a query would be overwritten by the code the next time a record is entered.
 
>>> The VBA code analyzed the choice of the other field and then sets the record source for the combo box.

It would be at that point you apply rjoubert's solution, for example:
Code:
MyComboBox.RecordSource = "SELECT MyIDField As [User ID], MyNameField As [User Name] FROM MyTable"
 
Thank you,

Actually, I just figured it out. Extremely simple..as most things are once you know them.

Thanks again to both of you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top