Access Passing the value to a table

Joined
Feb 16, 2018
Messages
1
Reaction score
0
Hi, I've got three tables. I want to create a form [unbound type] that passes the value of the form to the table. My form works like this, First I need to enter the customerID, second, I created a combo box which displays all of my products and the third one is my Quantity. I need to click the Add&Save button so that it will be inserted into my orderT but a problem occurs.

Private Sub Command17_Click()
Dim db As Database
Dim rec As Recordset

Set db = CurrentDb
Set rec = db.OpenRecordset("Select * from Order")=> This is my table to be insert with IDs from the other two tables.

rec.AddNew
rec("CustID") = Me.txtCustomerID /* I need to insert my ID of customer */
rec("ProdID") = Me.txtProdID /* I need to insert the product ID */
rec("Qty") = Me.txtQuantity /* I need to insert the quantity*/
rec.Update

Set rec = Nothing
Set db = Nothing

End Sub

After running I got this run-time error 3131, syntax error in FROM clause =>Set rec = db.OpenRecordset("Select * from Order")

Krishna
 
Joined
Mar 14, 2018
Messages
5
Reaction score
0
Try This
Private Sub cmdSaveRecord

Dim dB as Database
Dim Rs as Recordset

Set dB = currentdb
set Rs = dB.OpenRecordset("TableName", DbOpenTable)

with Rs
.AddNew
.Fields("CustID") = txtCustomerID 'Insert ID
.Fields("ProdID") = txtProdID
.Fields("Qty") = txtQuantity
.update
end with

set Rs = nothing
set dB = nothing

end sub
 

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