Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

append record with vba using formdocs

Status
Not open for further replies.

dcorleto

MIS
May 19, 2002
82
US
I am on a trial version of a program called Formdocs and have created a form that calls data from various tables in an Access database using ODBC. That's fine.

I have created another table in the database that I would like to hold the results of completed forms (includes subtotaled fields, etc). In the form design there is a place to enter vba code. How might I go about writing code for a command button on the form that would take selected fields from the form, and append them to the new table I created? I would imagine this can be done, but don't know if I am asking for the moon, or if this is relatively easy.
 
Here is built in code that is to export a record to a csv if this helps at all.

Private Sub BTN_EXPORT_Click ()
Dim PN As String

' Exports as CSV only the current record.
' Creates a file having the same name as the form with a ".csv" extension
' located on drive c:\. Appends subsequent exports to the end of the file.
' Change the pathname to meet your own needs.

On Error Goto Bad
If False = Thisform.Saved Then
MsgBox ("Please 'Save' the file before exporting!", 16)
Exit Sub
End If

PN = "c:\" & Thisform.name & ".csv"
PN = InputBox("Enter a pathname for the export file and click OK.", "Export Current Record", PN)
If (0 = Len(PN)) Then
Exit Sub
End If

Thisform.Export (PN, fdFormatText, fdRangeCurrentRecord, NULL, True, ",", True)
MsgBox ("To view the exported data, open file :" & PN, 64)
Exit Sub

Bad:
MsgBox("CSV Export Failed! " & Error(), 16)
End Sub
 
CSV thing, is irrelevant.

To append records to a table...

CurrentProject.Connection.Execute _
"INSERT INTO tblName (txtName, txtAddress, txtCity) VALUES('" & Me.txtName & "','" & Me.txtAddress & "','" & Me.txtCity & "')
 
Thank you so much for this start - I put the code into the appropriate place, changed the fields the the name and the table name and get an error -

parse error
object variable or object reference expected in procedure Export_Click at line 2

I'm a real novice, sorry..
 
Can't tell from here?

Could I see the complete code?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top