INSERT Problem

TheShed

New member
Local time
Today, 23:42
Joined
May 6, 2008
Messages
9
I am trying to insert a record into a table using the following code:-

CurrentDb.Execute ("INSERT INTO Jobs (startTime, finishTime, hoursWorked, description, mechanicID, nonProductive) VALUES ('" & txtstartTime.Text & "', '" & txtfinishTime.Text & "', '" & txthoursWorked.Text & "','" & txtdescription.Text & "','" & cmbmechanicNames.Value & "', '" & cbnonProductive.Value & "') ;")

But I am getting an error message saying I cannot reference a property or method of a control unless it has the focus.

Now obviously I can't set the focus for each of the control on the form where I am trying to get the values from in the INSERT statement, so what am I doing wrong?

*Edit - and if I use variables to get the values from the form rather than try and get them directly from the controls, and then use the values in the INSERT string, then the record isn't inserted to the table.
 
I am assuming that the controls that have a prefix of 'txt' are textboxes. If so, then you need to txtwhatever.value instead of txtwhatever.text.

HTH,
Chris
 
I am assuming that the controls that have a prefix of 'txt' are textboxes. If so, then you need to txtwhatever.value instead of txtwhatever.text.

HTH,
Chris

That get rids of the error message, but the record still doesn't insert. Any ideas?

My code is now:-

CurrentDb.Execute ("INSERT INTO Jobs (startTime, finishTime, hoursWorked, description, mechanicID, nonProductive) VALUES ('" & txtstartTime.Value & "', '" & txtfinishTime.Value & "', '" & txthoursWorked.Value & "','" & txtdescription.Value & "','" & cmbmechanicNames.Value & "', '" & cbnonProductive.Value & "') ;")
 
The code is right...unless you missed an ' somewhere that I can't see.

Are you leaving out any required fields or anything?
 

Users who are viewing this thread

Back
Top Bottom