Trying to save selected record from a form to a table

Joined
Mar 12, 2011
Messages
3
Reaction score
0
Hi: I need help with the below procedure:

Private Sub Ctl40OTHours_AfterUpdate()
On Error GoTo Err_Ctl40OTHours_AfterUpdate
Dim db As DAO.Database
Dim strSQL As String
Set db = CurrentDb
strSQL = "INSERT INTO NameHours ( ID, " _
& "Cost) " _
& "VALUES ('" & Forms("OVER-TIME TRACKING FORM").[frmTotalCost].Form.[ID] & "', " _
& "#" & Forms("OVER-TIME TRACKING FORM").[frmTotalCost].Form.[Cost] & "#); "
db.Execute strSQL, dbFailOnError
Set db = Nothing
exit_Ctl40OTHours:
Exit Sub
Err_Ctl40OTHours_AfterUpdate:
MsgBox Err.Description
Resume exit_Ctl40OTHours
End Sub

I am getting an error message as : microsoft office access can't find the field 'I ' referred to in your expression
 
Joined
Jan 13, 2011
Messages
3
Reaction score
0
& "VALUES ('" & Forms("OVER-TIME TRACKING FORM").[frmTotalCost].Form.[ID] & "', " _

Is it right that your ID should be written with single quotation mark? Normally, an ID can be written as an Integer ... Do you understand what I want to say?

Maybe:
& "VALUES (" & Forms("OVER-TIME TRACKING FORM").[frmTotalCost].Form.[ID] & ", " _
 
Joined
Mar 12, 2011
Messages
3
Reaction score
0
Is it right that your ID should be written with single quotation mark? Normally, an ID can be written as an Integer ... Do you understand what I want to say?
Sorry but I do not understand. I am still learing the access db. Please give me an example.
Maybe:
Sorry but I do not understand. I am still learing the access db. Please give me an example.
 

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