update form from a combobox

Traden

Registered User.
Local time
Today, 04:33
Joined
Mar 7, 2003
Messages
32
Hi,

i have a form witch is based on a table. It has 7 fields. I want a combox to select records out of an other table, then when selected it should update 3 fields with the data that is connected to the selected record, and then enter in 3 boxes additional data and save it to the other table. My prob is that i am not able code the VB for the textboxes, that the automaticly update themselfs when i do select a record with the combobox

pls help

thanks
 
You can reference a comboboxes' columns using the syntax me.myComboBox.column(x), where x is the column number (starting at 0 I believe). So in the comboboxes' OnChange event you just assign the values of the selected records columns to the fields in your form.

For Example:

me.firstField = me.myComboBox.Column(2)
me.secondField = me.myComboBox.Column(2)
etc.

In terms of updating the record of the combobox selected, as long as you know the primary key of the table you can just create a SQL statement as run it.

For example:

dim strSQL as string
strSQL = "UPDATE TABLENAME SET COLUMN_A = '" & me.firstField & "', COLUMN_B = '" & me.secondField & "' WHERE ..."
DoCmd.setWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True

Remeber that the you need to include all of the tables' primary key columns in the WHERE clause .
 

Users who are viewing this thread

Back
Top Bottom