PDA

View Full Version : Multiple Control Sources?



cbaker
10-23-2008, 02:47 PM
I am very new to VBA and have run in to an issue that I have not been able to find the solution to through web searches.

I have an ADP with an Access form connecting to a SQL Server database. On this form, I have a combo box that is populated by a stored proc going against another database on this SQL Server. I am pulling back 3 values in the sproc, am displaying 2 of them in the combo box and want the third value to display in a display-only text field upon selection.

The part I am having difficulty with is I have found the way to get this text box to display the related value from the combo box is to set it's Control Source to be the value of a column in the combo box. But how do I then write the value of the text box to the database upon submit? I have learned to use the control source to define the db field the control will write it's value to. Will I need to write an update statement to grab the value of this field and update the record after the submit writes the rest of the information to the DB?

Hopefully I've explained myself thoroughly enough. Thanks.

CreganTur
10-24-2008, 05:16 AM
Welcome to the forum- always good to see new members!

If I understand yuor question correctly you need to update a table with the value of a textbox.

The easiest way to do this would be to us the 'DoCmd.RunSQL' method and write a SQL Update statement that will run when your 'Submit' button is clicked.

Combining SQL and VBA variables/object values can be a little tricky, so if you have problems with it please post your SQL code.

HTH:thumb

cbaker
10-24-2008, 09:54 AM
Correct. My text box is a related display field based on the value chosen from a combo box. I need the value displayed in this text field then written to a table along with all the other information on the form. The rest I can use the control source to handle the insert upon submit. I had hoped there would be a way to handle the related display in the UI rather than writing code in the control source field and it therefore not inserting to the table.

I will research the RunSQL method you suggest. Thanks for the help.