Save Data to Table

  • Thread starter Thread starter jimmyx18
  • Start date Start date
J

jimmyx18

I have a table, query, and for created. I want to be able to create,
view, and edit records. I can currently create and view records
successfuly but am having trouble editing them. I use the following
code for my load button to load the data that was previously entered
on the table:

Private Sub cmbLoad_Click()

txtid = [cboMMCT].[Column](1)
txtsln = [cboMMCT].[Column](2)

End Sub

So to save the data in a text box back to the table I thought I could
just reverse the commands:

Private Sub cmbSave_Click()

[cboMMCT].[Column](1) = txtid
[cboMMCT].[Column](2) = txtsln

End Sub

When I do this, I get an error about references. Please let me know
the correct way to save an unbound box back to a specific record on a
table.

Thanks,
Jared
 
First thing, column references in combo boxes start with 0, so your code
indicates there are at least 3 columns. If this is correct, no problem;
otherwise you may need to change your references to 0 and 1.

One way to do this would be to create two bound text boxes on your form and
hide them. Then in the after update event of the combo box:

Me.txtid = [cboMMCT].[Column](1)
Me.txtsln = [cboMMCT].[Column](2)

That would eliminate the need for the command button. If you prefer to use
the command button, put the code there and don't put it in the combo's after
update.
 
Yes, I am already using Culumn 0 for something else. So putting the
Me.txtid = [cboMMCT].[Column](1) in the after update eventof the combo
box will save the changed info in the text box back to the table?
 
You'll have to forgive my ignorance on this issue. I think I am
missing the purpose of the hidden bound bokes. Would the Control
Source be set to =[cboMMCT].[Column](1) on the first hidden box and
=[cboMMCT].[Column](2) on the second hidden box? If so, How would I
relate the changed date in the non hidden boxes back to the table.
Lets assume the hidden boxes are named txthid1 and txthid2.
 
to put the values in the text boxs into the combos, use the form's current
event. Since you are not using the bound column of the combos, you will have
to populate the combos based on their bound columns.
 
Back
Top