Appending Data from a Form to a Table

  • Thread starter Thread starter T Liden
  • Start date Start date
T

T Liden

I need to append the data that is showing in a form to a table. How would I
go about doing that?

Thanks in advance for your time!!
Tim
 
Most of the controls are bound to a query's fields, but there are a few text
boxes that the user inputs some infomation into manually that needs to be
appended as well.

The user chooses a job # and then the info for that job comes up from the
query. The user then fills in the text boxes with the appropriate info and
then I want them to click on a button to append the data to an existing
table.

Thanks!!
 
Can't give you specifics since I don't know your database structure.

The code for the click event of the button would look SOMETHING like the
UNTESTED AIRCODE below

Dim dbAny as DAO.Database
Dim strSQL as String

StrSQL = "INSERT INTO Tablename ( [TextFieldA], [NumberFieldB] ) " & _
" VALUES( """ & Me.txtControlA & """, " & _
me.txtNumberControl & ")"

Debug.print StrSQL
STOP

Set dbAny = CurrentDb

dbany.execute strSQL, dbFailonError

But the question is still why are you doing this. If you have the values
through a relation to another table, you should only be storing the value to the
keyfield in that other table - probably in the table that you are using as the
source of the form.
 
Thanks for the help John!!

I wrote some code that works and adds the data from the form to the table.
If you see a problem with this code, please let me know. Thanks!!!

Private Sub Command24_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("Customers2")
Set frm = Forms("Customer Query")

With rst
..AddNew
!CustomerID = frm("CustomerID")
!Notes = frm("Text27")
..Update
End With

End Sub
John Spencer (MVP) said:
Can't give you specifics since I don't know your database structure.

The code for the click event of the button would look SOMETHING like the
UNTESTED AIRCODE below

Dim dbAny as DAO.Database
Dim strSQL as String

StrSQL = "INSERT INTO Tablename ( [TextFieldA], [NumberFieldB] ) " & _
" VALUES( """ & Me.txtControlA & """, " & _
me.txtNumberControl & ")"

Debug.print StrSQL
STOP

Set dbAny = CurrentDb

dbany.execute strSQL, dbFailonError

But the question is still why are you doing this. If you have the values
through a relation to another table, you should only be storing the value to the
keyfield in that other table - probably in the table that you are using as the
source of the form.


T said:
Most of the controls are bound to a query's fields, but there are a few text
boxes that the user inputs some infomation into manually that needs to be
appended as well.

The user chooses a job # and then the info for that job comes up from the
query. The user then fills in the text boxes with the appropriate info and
then I want them to click on a button to append the data to an existing
table.

Thanks!!
If
so, you code
to do so. an
append
 
Back
Top