Connecting Tech Pros Worldwide Forums | Help | Site Map

Datatype Mismatch

Familiar Sight
 
Join Date: Nov 2007
Posts: 145
#1: Jan 15 '09
Does anyone know where my error is on this? I keep getting a data type mismatch error.

My fields and their type are:

EmployeeID - Text
OTDate - Date
HoursPay - Double
RateofPay - Currency
TypeOfJob - integer
Notes - text
ID - Autonumber

My Code is as follows:

<Code>
Dim intTypeOfJob As Integer
Dim strSQL As String
Dim dblHoursPay As Double
If [TypeOfJob] = 1 And [HoursPay] > 8 Then
intTypeOfJob = 99
dblHoursPay = [HoursPay] - 8
strSQL = "INSERT INTO tblOvertime VALUES (""" & EmployeeID _
& """, #" & OTDate & "#, " & dblHoursPay & ", " & RateOfPay & ", " _
& intTypeOfJob & ", """ & Notes & """," & ID & ")"
CurrentDb.Execute strSQL, dbFailOnError
End If
<End Code>

Thanks

RuralGuy's Avatar
Expert
 
Join Date: Oct 2006
Posts: 194
#2: Jan 15 '09

re: Datatype Mismatch


You have not specified the fields into which to insert the Values().
Familiar Sight
 
Join Date: Nov 2007
Posts: 145
#3: Jan 15 '09

re: Datatype Mismatch


How would I do that my fields are:
EmployeeID - Text
OTDate - Date
HoursPay - Double
RateofPay - Currency
TypeOfJob - integer
Notes - text
ID - Autonumber

I am very new at this and am learning from this site

Thanks
Dan
RuralGuy's Avatar
Expert
 
Join Date: Oct 2006
Posts: 194
#4: Jan 15 '09

re: Datatype Mismatch


Try something like:
Expand|Select|Wrap|Line Numbers
  1. Dim intTypeOfJob As Integer
  2. Dim strSQL As String
  3. Dim dblHoursPay As Double
  4. If [TypeOfJob] = 1 And [HoursPay] > 8 Then
  5.    intTypeOfJob = 99
  6.    dblHoursPay = [HoursPay] - 8
  7.    strSQL = "INSERT INTO tblOvertime (EmployeeID, OTDate, HoursPay, " & _
  8.             "RateofPay, TypeOfJob, Notes, ID) " & _
  9.             "VALUES (""" & EmployeeID & """, #" & OTDate & "#, " & dblHoursPay & _
  10.             ", " & RateOfPay & ", " & intTypeOfJob & ", """ & Notes & """," & ID & ")"
  11.    CurrentDb.Execute strSQL, dbFailOnError
  12. End If
Familiar Sight
 
Join Date: Nov 2007
Posts: 145
#5: Jan 15 '09

re: Datatype Mismatch


Yes that is almnost it!!!!!!!!!!!!!!! except I had to remove the ID field because it was autonumber. Now it works!!!!!!!!!!!!

Thankyou
RuralGuy's Avatar
Expert
 
Join Date: Oct 2006
Posts: 194
#6: Jan 15 '09

re: Datatype Mismatch


You're welcome. Thanks for posting back with your success.
Reply

Tags
data type mismatch