0

For starters, I have practically no knowledge of VBA Code. What I'm trying to do here is take information from a form and subform and enter it as a new record into a table that is set as the record source of the subform.

The error code reads: run time error '3075':

Syntax Error (Missing Operator) in query expression 'GENERAL METAL (CUBEX)'.

Also I apologize for how messy it is. I honestly just tried to copy what I saw in a YouTube video that kind of represented what I was trying to do.

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
  • 2
    This probably isn't an Access error and is actually a SQL error. Store your dynamic SQL into a variable and provide the actual query. Or just print it to your immediate window: replace CurrentDb.Execute with debug.print. It's going to be nearly impossible for anyone else to debug what you've provided. Commented Jul 12, 2013 at 17:18
  • I'd love to make it easier to read but I have no idea what you've just asked me to do there. Commented Jul 12, 2013 at 17:24
  • If you want a multi-line query in VBA, you need to add & _ to all but the last line. Reformat your code if that is not happening. Also, if your date fields are dates and not strings, replace the single quotations marks with #. Commented Jul 12, 2013 at 17:38
  • Try first to execute a much simpler INSERT statement, using only a few fields. Then add additional fields. This is generally good advice and will also help you to discover the cause of the problem. Commented Jul 12, 2013 at 17:53

1 Answer 1

3

This part concerns me: '" & Me.moldlocation & _ Me.specialconcerns & "'

It looks like you're missing the closing quote before the line suppression. Any time you see "& _" it's telling the code that you're moving to a new line, but to supress that line break when the code is run. You generally need to close up your quotes before you do that, just like was done in the other line suppressor: qtycast) " & _ " VALUES(

So, in short, give this a shot:

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 & "')"

Since I don't know your data, I'll just remind you that anything that's TEXT needs to be enclosed with single quotes (i.e. '" & Me.grade & "',) and anything that's an INT does not need the single quote (i.e. " & Me.customer & ",). Just make sure all your variables are enclosed accordingly or that will cause an error as well.

If this answers your question, please don't forget to give the answer a checkmark. Thanks!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.