Insert fields from sub form into db using sql and vba

Gavx

Registered User.
Local time
Today, 17:38
Joined
Mar 8, 2014
Messages
155
I am trying to formulate some code to run an SQL statement but it is not working.

The statement runs from a button on the sub form subOriginForm. Its intention is to collect the values from cboField1 and txtfield2 located on that form and insert them into tblTargetDB - but the whole thing isn't working.

Can someone advise me why please.

Code below
Thanks


Code:
Private Sub cmdMyButton_Click()

'DoCmd.SetWarnings False

INSERT INTO tblTargetDB ( field1, field2)
VALUES (forms!subOriginForm.cboField1, forms!subOriginform.txtfield2);

    DoCmd.SetWarnings True

End Sub
 
Why do you need code to save the value of controls on the sub form. Forms and thier controls are usually bound to a table or query and the values are then saved each time the user moves to a different or new record.
 
If I understand correctly, I am utilizing the values in the text boxes because the subform and these values still have focus and their underlying values are still available.
 
If I understand correctly, I am utilizing the values in the text boxes because the subform and these values still have focus and their underlying values are still available.
I'm not sure what that means but if you are trying to save edited values without moving to another record try:

Me.Dirty = False
 
When working with the Database and something goes wrong you really want to know about it.

DoCmd.SetWarnings True

This sort of thing gives a false impression. If you have an error then you can get stuck between ON and Off. And you don't really know which.

It would be better to leave this alone.
 

Users who are viewing this thread

Back
Top Bottom