访问VBA - 运行时错误'3075'

时间:2013-07-12 17:08:16

标签: vba ms-access access-vba

对于初学者,我几乎不了解VBA代码。我在这里要做的是从表单和子表单中获取信息,并将其作为新记录输入到设置为子表单记录源的表中。

错误代码为:运行时错误'3075':

查询表达式'GENERAL METAL(CUBEX)'中的语法错误(缺少运算符)。

我也为它有多乱而道歉。老实说,我只是试图复制我在YouTube视频中看到的那种代表我想要做的事情。

CurrentDb.Execute "INSERT INTO workingorders(customer, partname, partnumber, metal, grade, unitweight, Process, subcontract, MoldDescription, moldlocation, specialconcerns, shippinginst, datereq, orderdate, qtyordered, qtycast) " & _
" VALUES(" & Me.customer & ", '" & Me.partname & "','" & Me.partnumber & "','" & Me.metal & "','" & Me.grade & "','" & Me.unitweight & "','" & Me.Process & "','" & Me.subcontract & "','" & Me.MoldDescription & "','" & Me.moldlocation & _
Me.specialconcerns & "','" & Me.shippinginst & "','" & Me.datereq & "','" & Me.orderdate & "','" & Me.qtyordered & "','" & Me.qtycast & "')"

1 个答案:

答案 0 :(得分:3)

这部分关注我: '“& Me.moldlocation& _ Me.specialconcerns&”'

在线路抑制之前,您似乎错过了收盘报价。任何时候你看到“& _”它告诉代码你正在转移到一个新行,但是在代码运行时压制该换行符。在执行此操作之前,通常需要关闭引号,就像在其他行抑制器中完成一样: qtycast)“& _”VALUES(

所以,简而言之,请试一试:

CurrentDb.Execute "INSERT INTO workingorders(customer, partname, partnumber, metal, grade, unitweight, Process, subcontract, MoldDescription, moldlocation, specialconcerns, shippinginst, datereq, orderdate, qtyordered, qtycast) " & _ 
" VALUES(" & Me.customer & ", '" & Me.partname & "','" & Me.partnumber & "','" & Me.metal & "','" & Me.grade & "','" & Me.unitweight & "','" & Me.Process & "','" & Me.subcontract & "','" & Me.MoldDescription & "','" & Me.moldlocation "'," & _ 
"'" & Me.specialconcerns & "','" & Me.shippinginst & "','" & Me.datereq & "','" & Me.orderdate & "','" & Me.qtyordered & "','" & Me.qtycast & "')"

由于我不知道您的数据,我只是提醒您,任何TEXT都需要用单引号括起来(即'“& Me.grade&”'),而任何INT都是不需要单引号(即“& Me.customer&”,)。只需确保所有变量都相应地包含在内,否则也会导致错误。

如果这回答了您的问题,请不要忘记给答案一个复选标记。谢谢!