Append Data in Table from VB

  • Thread starter mattc66 via AccessMonster.com
  • Start date
M

mattc66 via AccessMonster.com

I have a form with data that the user has input. When they click a print
button on my form, I want certain feilds of data to append another table in
my database, but is not part of the form that contains the button.

How would I write the code to do this. The below code is not working.

Private Sub cmdPrint_Click()

Dim stLinkCriteria As String

stLinkCriteria = "[OrderNum]=" & "'" & [OrderNum] & "'"

If DCount("OrderNum", "tblOrders", stLinkCriteria) >= 1 Then

Table!ProductionPlanner!ShipID = Forms!frmShipmain!ShipID
Table!ProductionPlanner!ShipDate = Forms!frmShipmain!ShipDate
Table!ProductionPlanner!TrackingNum = Forms!frmShipmain!TrackingNum

End If
End Sub
 
G

Graham R Seach

Matt,

Private Sub cmdPrint_Click()
Dim db As Database
Dim strSQL As String

On Error Resume Next
Set db = CurrentDb

strSQL = "INSERT INTO ProductionPlanner " & _
"(ShipID, ShipDate, TrackingNum) " & _
"VALUES (" & Forms!frmShipMain!ShipID & ", " & _
CDbl(Forms!frmShipMain!ShipDate) & ", " & _
Forms!frmShpMain!TrackingNum & ")"

db.Execute strSQL, dbFailOnError
If (Err <> 0) Then
MsgBox "Could not add new record"
End If

Set db = Nothing
End Sub

If frmShipMain is the current form, you can replace Forms!frmShipMain with
the Me keyword:
strSQL = "INSERT INTO ProductionPlanner " & _
"(ShipID, ShipDate, TrackingNum) " & _
"VALUES (" & Me!ShipID & ", " & _
CDbl(Me!ShipDate) & ", " & _
Me!TrackingNum & ")"

Regards,
Graham R Seach
Microsoft Access MVP
Canberra, Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top