0

首先,我对 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 & "')"
4

1 回答 1

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&”,)。只需确保所有变量都相应地包含在内,否则也会导致错误。

如果这回答了您的问题,请不要忘记给答案打勾。谢谢!

于 2013-07-12T18:04:47.000 回答