条件表达式Access 2010与SQL Insert语句中的数据类型不匹配

条件表达式Access 2010与SQL Insert语句中的数据类型不匹配,sql,ms-access,vba,Sql,Ms Access,Vba,我试图更新access中的链接表,但在条件表达式中出现数据不匹配类型的错误。唯一浮动的数据库字段是以小时开头的字段 我尝试将小时字段设置为整数值,但收到了不同类型的不匹配消息 我是VB和access的新手,所以它可能是一些愚蠢的东西。谢谢你的帮助。这是我的密码 Private Sub Command30_Click() Dim monthFormat As String Dim yearFormat As String Dim fullYear As String Dim datePerform

我试图更新access中的链接表,但在条件表达式中出现数据不匹配类型的错误。唯一浮动的数据库字段是以小时开头的字段

我尝试将小时字段设置为整数值,但收到了不同类型的不匹配消息

我是VB和access的新手,所以它可能是一些愚蠢的东西。谢谢你的帮助。这是我的密码

Private Sub Command30_Click()
Dim monthFormat As String
Dim yearFormat As String
Dim fullYear As String
Dim datePerformed As String
Dim currDate As String
Dim timeEntered As String
Dim empNum As String
Dim acct As String
Dim cat As String
Dim cmnt As String
Dim firstName As String
Dim lastName As String
Dim shift As String
Dim addVacation As String
Dim hours As String

If IsNumeric(Me.Text12.Value) Then hours = CInt(Me.Text12.Value) Else: hours = Me.Text12.Value

monthFormat = Format(Me.Text10.Value, "MM")
yearFormat = Format(Me.Text10.Value, "YY")
fullYear = Format(Me.Text10.Value, "YYYY")
datePerformed = Format(Me.Text10.Value, "YYYYMMDD")
currDate = Format(DateTime.Date, "YYYYMMDD")
timeEntered = Format(DateTime.Time, "HHMMSS")
empNum = " & Me.Combo20.Column(0) & "
acct = " & Me.Combo20.Column(1) & "
cat = " & Me.Combo20.Column(3) & "
cmnt = " & Me.Combo20.Column(4) & "
firstName = " & Me.Combo20.Column(5) & "
lastName = " & Me.Combo20.Column(6) & "
shift = " & Me.Combo20.Column(7) & "
hours = " & Me.Text12.Value & "

addVacation = "insert into dbo_R_PPHRTRX" & _
"(DATE_PERFORMED, EMPLOYEE_NUMBER " & _
", JOB_NUMBER " & _
", RELEASE " & _
", ACCOUNT, ACCOUNT_CR, BATCH_ITEM, BATCH_NUMBER, BURDEN_DOLLARS, CATEGORY, DATE_TIME_BEGUN,         DATE_TIME_COMPLT, EFF_VAR_DOLLARS, EMPLOYEE_ID, EO_FLAG, FIRST_NAME " & _
", HOURS_EARNED, HOURS_WORKED, HOURS_WORKED_SET, LABOR_DOLLARS, LAST_NAME, LOCATION_CODE,     PERIOD_YYYYMM, PRODUCT_LINE, QTY_COMPLETE, RATE_VAR_DOLLARS " & _
", RELEASE_WO " & _
", SHIFT, [STATUS], [TIME], WORK_CENTER, DATE_ENTERED, DivisionID, Comment " & _
", LATE_CHARGE, OPERATION, OVERTIME, PROJECT_TASK, REFERENCE, TASK_NUMBER, TYPE_TRANSACTION,     DATACAPSERIALNUMBER, COST_ACCOUNT, CS_PERIOD, WORK_ORDER) " & _
" " & _
"  VALUES('" & datePerformed & "' , '" & empNum & "'  " & _
", switch(('" & monthFormat & "' >= 1 And '" & monthFormat & "' <= 3), ('01VH' + '" & yearFormat     & "'), ('" & monthFormat & "' >= 4 And '" & monthFormat & "' <= 6), ('02VH' + '" & yearFormat & "'),     ('" & monthFormat & "' >= 7 And '" & monthFormat & "' <= 9), ('03VH' + '" & yearFormat & "'), ('" &     monthFormat & "' >= 10 And '" & monthFormat & "' <= 12), ('04VH' + '" & yearFormat & "'))" & _
", switch(('" & monthFormat & "' >= 1 And '" & monthFormat & "' <= 3), ('01VH' + '" & yearFormat     & "'), ('" & monthFormat & "' >= 4 And '" & monthFormat & "' <= 6), ('02VH' + '" & yearFormat & "'),     ('" & monthFormat & "' >= 7 And '" & monthFormat & "' <= 9), ('03VH' + '" & yearFormat & "'), ('" &     monthFormat & "' >= 10 And '" & monthFormat & "' <= 12), ('04VH' + '" & yearFormat & "'))" & _
", '" & acct & "', '2500-X', '0', '0', '0', 'LABOR HRS', '" & datePerformed & "'  + '0600', '" &     datePerformed & "' + '0600', '0', 'ACCSS', '', '" & firstName & "' " & _
", '" & hours & "', '" & hours & "', '0', '0', '" & lastName & "', '01', '" & fullYear & "' + '"     & monthFormat & "', '01', '0', '0' " & _
", switch(('" & monthFormat & "' >= 1 And '" & monthFormat & "' <= 3), ('01VH' + '" & yearFormat     & "'), ('" & monthFormat & "' >= 4 And '" & monthFormat & "' <= 6), ('02VH' + '" & yearFormat & "'),         ('" & monthFormat & "' >= 7 And '" & monthFormat & "' <= 9), ('03VH' + '" & yearFormat & "'), ('" &                  monthFormat & "' >= 10 And '" & monthFormat & "' <= 12), ('04VH' + '" & yearFormat & "'))" & _
", '" & shift & "', '', '" & timeEntered & "', '92', '" & currDate & "', 'Jobscope', 'V' " & _
", '', '', '', '', '', '', '', '', '', '', '')"    

DoCmd.RunSQL (addVacation)


End Sub
Private子命令30_Click()
Dim monthFormat作为字符串
格式为字符串
整年如弦
作为字符串执行
将日期设置为字符串
作为字符串输入的Dim TIME
将empNum设置为字符串
作为字符串的Dim acct
暗猫如弦
作为字符串的Dim cmnt
将firstName设置为字符串
将lastName设置为字符串
作为字符串的暗移
将假期作为字符串添加
暗淡无光
如果是数字(Me.Text12.Value),则小时数=CInt(Me.Text12.Value),否则:小时数=Me.Text12.Value
monthFormat=格式(Me.Text10.Value,“MM”)
yearFormat=格式(Me.Text10.Value,“YY”)
fullYear=格式(Me.Text10.Value,“YYYY”)
datePerformed=格式(Me.Text10.Value,“yyyyymmdd”)
currDate=格式(DateTime.Date,“yyyyymmdd”)
输入的时间=格式(DateTime.Time,“HHMMSS”)
empNum=“&Me.Combo20.列(0)&”
acct=“&Me.Combo20.第(1)列和”
cat=“&Me.Combo20.第(3)列和”
cmnt=“&Me.Combo20.第(4)列和”
firstName=“&Me.Combo20.列(5)&”
lastName=“&Me.Combo20.列(6)和”
shift=“&Me.Combo20.列(7)和”
hours=“&Me.Text12.Value&”
addVacation=“插入dbo_R_PPHRTRX”&_
“(执行日期、员工编号”和_
“,工作编号”和_
",发布"及_
“、科目、科目、批次项目、批次编号、负担金额、类别、开始日期时间、完成日期时间、有效金额、员工ID、EO标志、名字”&_
“、已赚工时、已工作工时、已工作工时集、人工美元、姓氏、地点代码、期间(YYYYMM)、产品线、完成数量、费率(VAR)美元”&_
"发布"及_
“、班次、[状态]、[时间]、工作中心、输入日期、部门ID、备注”&_
“、滞纳金、运营、加班、项目任务、参考、任务编号、交易类型、DATACAPSERIALNUMBER、成本账户、CS周期、工单”&”_
" " & _
“值('”&datePerformed&“,'”&empNum&“'”&_
“、开关(“&monthFormat&”>=1和“&monthFormat&”=4和“&monthFormat&”=7和“&monthFormat&”=10和“&monthFormat&”=1和“&monthFormat&”=4和“&monthFormat&”=7和“&monthFormat&”=10和“&monthFormat&”=1和“&monthFormat&”=4和“&monthFormat&”=7和”和MunthFrand和“‘10’和‘MunthFrand’”’P>而不是“粘在一起”一个长的、丑陋的和潜在的麻烦插入语句,您可以考虑使用记录集对象插入新行:

Dim cdb作为DAO.Database,rst作为DAO.Recordset
设置cdb=CurrentDb
Set rst=cdb.OpenRecordset(“从dbo_R_PPHRTRX中选择*,其中为False”,dbOpenDynaset)
rst.AddNew
rst!执行日期=执行日期
rst!员工编号=empNum
“……其他领域也是如此
rst.更新
rst.关闭
设置rst=无
设置cdb=无

感谢您的帮助。是“粘在一起”字符串以及其他一些东西导致了问题。我制作了开关变量,因此它在VBA查询中而不是SQL查询中进行计算,一切正常


再次感谢。

在“DoCmd.RunSQL(addVacation)”行中放置一个断点,并检索“addVacation”的值。然后在此处发布查询。dbo\u r\u PPHRTRX中的所有字段是否都实际格式化为文本?