save button on form

  • Thread starter Thread starter ANGELA
  • Start date Start date
A

ANGELA

I am trying to save data on a form back to a table but need to use the query
for the form as they are all combo boxes and don't have the control source
filled in. Does anyone have any suggestions on how to make the code work so
I can click on save and the data go back to the designated table for
reporting.


Thanks
 
Angela,

Is there a good reason why these fields are not bound to the table? This
would be my recommendation, unless you have a really good reason for not
doing it this way.

If you need to insert a record into the table, you could write an insert
query via code and run it on the Click event of the Save button.

Private Sub cmdSave_Click

Dim strSQL as string

strSQL = "INSERT INTO tblYourTable (Field1, Field2, Field3) " _
& "Values (" & me.cbo1 & ", " _
& me.cbo2 & ", " _
& me.cbo3 & ")"
currentdb.execute strSQL, dbfailonerror

End Sub

If the combo boxes contain text, rather than numbers you would need to wrap
the values in quotes, something like:

strSQL = "INSERT INTO tblYourTable (Field1, Field2, Field3) " _
& "Values ('" & me.cbo1 & "', '" _
& me.cbo2 & "', '" _
& me.cbo3 & "')"
 
Back
Top