473,382 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Syntax Error Missing Operator but Where?

Hey guys, I'm using an embedded sql statement tied to a command button to append records in a certain table. The code for the sql statement is as follows.
Expand|Select|Wrap|Line Numbers
  1. 'Define sql string
  2. strSQL = "INSERT INTO LPID (LPName, LPUnitPrice, VendorFamily, LPCatagoryID, LPStructure)" & _
  3. "SELECT LPID.LPName, LPID.LPUnitPrice, LPID.VendorFamily, LPID.LPCatagoryID, LPID.LPStructure" & _
  4. "FROM LPID" & _
  5. "WHERE (([LPID.LPName] = [Forms]![Investment Manager]![subfrmVendor]!LPName)" & _
  6. "([LPID.LPUnitPrice] = [Forms]![Investment Manager]![subfrmVendor]!LPUnitPrice)" & _
  7. "([LPID.VendorFamily] = [Forms]![Investment Manager]![subfrmVendor]!VendorFamily)" & _
  8. "([LPID.LPCatagoryID] = [Forms]![Investment Manager]![subfrmVendor]!LPCatagoryID)" & _
  9. "([LPID.LPStructure] = [Forms]![Investment Manager]![subfrmVendor]!LPStructure));"
  10.  
  11. 'Run Sql
  12. DoCmd.RunSQL strSQL
  13.  
It gives me an error saying syntax error(missing operator), but I can't seem to find where the error is. Any help would be appreciated.
Mar 6 '07 #1
10 2073
Rabbit
12,516 Expert Mod 8TB
You need spaces. Also, you may need to change [Forms]![Main Form]![Sub Form]![Control Name] to [Forms]![Main Form]![Sub Form]![Form]![Control Name] but I'm not entirely sure about this.
Expand|Select|Wrap|Line Numbers
  1. 'Define sql string
  2. strSQL = "INSERT INTO LPID (LPName, LPUnitPrice, VendorFamily, LPCatagoryID, LPStructure)" & _
  3. " SELECT LPID.LPName, LPID.LPUnitPrice, LPID.VendorFamily, LPID.LPCatagoryID, LPID.LPStructure" & _
  4. " FROM LPID" & _
  5. " WHERE (([LPID.LPName] = [Forms]![Investment Manager]![subfrmVendor]!LPName)" & _
  6. " ([LPID.LPUnitPrice] = [Forms]![Investment Manager]![subfrmVendor]!LPUnitPrice)" & _
  7. " ([LPID.VendorFamily] = [Forms]![Investment Manager]![subfrmVendor]!VendorFamily)" & _
  8. " ([LPID.LPCatagoryID] = [Forms]![Investment Manager]![subfrmVendor]!LPCatagoryID)" & _
  9. " ([LPID.LPStructure] = [Forms]![Investment Manager]![subfrmVendor]!LPStructure));"
  10.  
  11. 'Run Sql
  12. DoCmd.RunSQL strSQL
  13.  
Mar 6 '07 #2
Thanks rabbit, that along with adding AND's on all of the 'WHERE' statements fixed the error. Now though, It doesn't give an error, but it also does not 'see' any data to append to the table LPID. The whole purpose of this sql statement was because I have a subform that is to update a table. That subform though was not updating the table even though it's control was set to the proper control for that table. I also was worried about users entering data and not really wanting it. This way, the sql statement will only run after the submit button is clicked. This should cut down on the amount of bad data tremondously.

Any other help you can give me on this problem would be greatly appreciated.
Mar 6 '07 #3
Rabbit
12,516 Expert Mod 8TB
I would try to get this append query working in a regular query and then just copy it's SQL from the SQL view.
Mar 6 '07 #4
Ok Rabbit, I've decided to go a different route, but even this new route I'm having trouble with. I've decided against using an append query and instead have the information entered into the table through the subform. The subform has a few places to enter data that go directly into the table. If you close the form with the 'x' and then check the corrosponding table it works fine. For this application though, this does not work. At times the user will need to enter several "sheets" of data at once. So, what I have done is added a 'submit' button. The purpose of the button is so that when the user is finished with that "sheet" of data they hit submit. This should then produce a msgbox that says "your data has been submitted successfully". And then it should wipe the two combo boxes and the 4 text boxes so that it is waiting for a new set of data. I've gotten the msgbox to work *although it pop's up unconditionally, meaning whether or not the data was actually added it pops up and says that it has added it* I can also wipe all of the text boxes. I cannot however 'wipe' the two combo boxes. That though is not the biggest problem. The biggest problem is that after hitting the button and all this taking place if I close the form and then check my table, nothing has been added! To me this seems weird especially since the data that has been entered as been assigned an autonumber value.
I really don't know what's wrong with it or why it is not adding the data to the table. If this explanation is to convuleted for you to understand please ask any question that you need to. Thank you again for your help.
Mar 6 '07 #5
Rabbit
12,516 Expert Mod 8TB
The problem is that when you clear the data, you're actually clearing the record which then auto saves to the table. Rather than clearing the fields manually, have the form go to a new record and that should take care of everything.
Mar 6 '07 #6
I did not realize that you could 'force a new record' via VBA. So, if I'm understanding you right what I would do is take this VBA command and tie it to the submit button? I'll have to go look up the command and try that. Also, is there any way for that msg box to popup conditionally. I.e. check to make sure that the record did in fact get updated in the table? Thank you again!
Mar 6 '07 #7
Oh wow!! Ok, I just tried the gotorecord method and it worked splendidly. Thank you for your help Rabbit.

If there isn't a way to check for the new record to make sure that it did submit before printing the msgbox just let me know. Thank you again!
Mar 6 '07 #8
Rabbit
12,516 Expert Mod 8TB
If the form is bound to the table then Access takes care of all updates automatically. As long as you get rid of the code that's clearing out the fields when you hit submit, whatever's typed into the form will be saved to the table automatically. Actually, the data gets saved before you ever hit the submit button. Most of the time, the submit button doesn't actually tell the form to save the data to a table because the table is already bound to the form.
Mar 6 '07 #9
If the form is bound to the table then Access takes care of all updates automatically. As long as you get rid of the code that's clearing out the fields when you hit submit, whatever's typed into the form will be saved to the table automatically. Actually, the data gets saved before you ever hit the submit button. Most of the time, the submit button doesn't actually tell the form to save the data to a table because the table is already bound to the form.
Alright, that makes sense and is actually what I assumed would be happening. It's just weird I guess to run across things like that and then look back at other programs that you've used and wonder / realize that a lot of the things in the gui are just superfluous and aren't really 'reporting' anything. Thanks again for your help rabbit!
Mar 7 '07 #10
Rabbit
12,516 Expert Mod 8TB
Not a problem, come back if you have any more questions.
Mar 7 '07 #11

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

Similar topics

29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
1
by: Alan Murrell | last post by:
Hello, One of our web hosting clients is getting the following error when someone tried to log in form their login page: --- ODBC ERROR --- Microsoft OLE DB Provider for ODBC Drivers error...
4
by: khan | last post by:
getting, error, 3075 Syntax Error (Missing Operator) in query expression '8WHERE .=1' Dim TotalQty As Integer TotalQty = DLookup("", "", "=" & Forms!!)
3
by: access baby | last post by:
I hava a date parameter filter query but it shows error Syntax error missing operator in query experssion can some one please help where am i going wrong in expression SELECT copyorderdtl * ...
5
by: UAlbanyMBA | last post by:
I am getting a syntax error missing operator when I try to created a record set by selecting a record from a list box. I do not know where the error is though. Everything looks good, as a matter of...
4
by: nerd4access | last post by:
Hello all! I am not new to access, but new to coding (and posting). I have a database that I have created and need some help with a login form. When a user opens the database, a form pops up...
2
by: aaron6098 | last post by:
I am trying to finish my final project for my programing class. i keep on getting Error Type: Microsoft OLE DB Provider for ODBC Drivers (0x80040E14) Syntax error (missing operator) in query...
5
by: vbnewbiee | last post by:
i am working on this code for my password change option in my vb6 program. with access as backend. but im encountering errorline "syntax error(missing operator) in query expression on my update...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.