By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,248 Members | 1,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,248 IT Pros & Developers. It's quick & easy.

Datatype Mismatch

100+
P: 147
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
Jan 15 '09 #1
Share this Question
Share on Google+
5 Replies


RuralGuy
Expert 100+
P: 375
You have not specified the fields into which to insert the Values().
Jan 15 '09 #2

100+
P: 147
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
Jan 15 '09 #3

RuralGuy
Expert 100+
P: 375
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
Jan 15 '09 #4

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

Thankyou
Jan 15 '09 #5

RuralGuy
Expert 100+
P: 375
You're welcome. Thanks for posting back with your success.
Jan 15 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.