Hi all. i'm trying to learn how to write paramterized queries. from what i've pieced together on the internet i've made a few efforts. i'm having trouble though and i'm sure it's something i'm not doing right.
here is my insert code and parameters i'm trying to enter. i have ms access 2003:
after i try and run this the application errors out with a type mismatch. i have tried changing numerous fields around tring different "ad-" types and all come with the same result. my database column id's are what is shown above. i put a msgbox catch in the code right before and right after the with statement. i see the msgbox before but not after. so i'm getting thrown out at the with statement. the code is fine and the insert string looks good up to that point.
all of this code is together in the onclick event of a save button.
What am i doing wrong?
Thanks
here is my insert code and parameters i'm trying to enter. i have ms access 2003:
Code:
insstr = "INSERT INTO downtimetable ( [Mechanic Name], Shift, [Line Number], [Machine Description], [Failure Point], [Cause of Failure], [Estimated Time], [Equipment Number], [WO Status] )" & _
"VALUES (@stoName, @stoDate, @stoShift, @stoLine, @stoMachine, @stoFailure, @stoCause, @stoEstTime, @stoEquipment_Number, @stoWOStatus);"
msgbox insstr, vbOKOnly, "test"
With cmd
Set .ActiveConnection = conn
.CommandText = insstr
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("stoName", adVarChar, adParamInput, Len(cboUsername.value), cboUsername.value)
.Parameters.Append .CreateParameter("stoDate", adDate, adParamInput, Len(txtDate), txtDate)
.Parameters.Append .CreateParameter("stoShift", adInteger, adParamInput, Len(txtShift), txtShift)
.Parameters.Append .CreateParameter("stoLine", adVarChar, adParamInput, Len(cboLine.value), cboLine.value)
.Parameters.Append .CreateParameter("stoMachine", adVarChar, adParamInput, Len(cboMachine.value), cboMachine.value)
.Parameters.Append .CreateParameter("stoFailure", adVarChar, adParamInput, Len(cboFailure.value), cboFailure.value)
.Parameters.Append .CreateParameter("stoCause", adVarChar, adParamInput, Len(txtFailure), txtFailure)
.Parameters.Append .CreateParameter("stoEstTime", adInteger, adParamInput, Len(txtEstTime), txtEstTime)
.Parameters.Append .CreateParameter("stoEquipment_Number", adInteger, adParamInput, Len(txtEquipment_Number), txtEquipment_Number)
.Parameters.Append .CreateParameter("stoWOStatus", adVarChar, adParamInput, Len(chkstatus), chkstatus)
End With
after i try and run this the application errors out with a type mismatch. i have tried changing numerous fields around tring different "ad-" types and all come with the same result. my database column id's are what is shown above. i put a msgbox catch in the code right before and right after the with statement. i see the msgbox before but not after. so i'm getting thrown out at the with statement. the code is fine and the insert string looks good up to that point.
all of this code is together in the onclick event of a save button.
What am i doing wrong?
Thanks