ADODB connection refuses to connect due to missing operator - sql

I'm opening an excel sheet via ADODB connection. The code has been working fine, until today, when it refused to connect to a new excel file.
The SQL string I am using is:
SELECT container_key,
price_catalogue,
portfolio_type,
portfolio_subtype,
yearly_fee,
yearly_fee_factor,
yearly_fee_2,
value_1,
advisory_agreement__advisory,
value_1_29,
3rd_party_key
FROM [temp0$]
Now I get an error message from VBA when i am on the line that is supposed to open the recordset:
Syntax error (missing operator) in query expression '3rd_party_key'
I have verified that the field exists and is named the same in the spreadsheet. The syntax looks correct to me as well. The spreadhseet is extremly large (360+ columns) and the field that is refrenced in the error message is the very last column. Might this have somethingto do with the issue I am encountering?
Can someone point out what the problem might be?
UPDATE:
I have tried putting all field names in parentheses. While this worked in not producing a run time error and it didn't work either. Finally I tried reducing the number of fields and went one by one. The following 3 fields cause the errors:
advisory_agreement__advisory,
value_1_29,
3rd_party_key
If i remove these fields, I can open the recordset without a problem. I suspect the name conventions of these fields causes a conflict somehow.

I'd try it column by column, with square brackets, to see which column is actually causing the problem. It might seem a bit tedious but this way you will know exactly where the problem lies.

Related

ms access query expression field not accepting IIf expression

im trying to return 1 if null and 0 if not null and when i enter the expression this The error
error pops up.
heres the expression i wrote :
IIf(IsNull([_characterType]); 0; 1)
The database file (i had to empty it for legal reasons)
(the database was in another language with special characters and i changed all of it to english, that may be the problem but i still dont know how to fix it)
i tried using comma instead of semicolon and got the same result.
when i enter the same exact expression in SQL view it works but when i switch to design view it breaks again.
i tried using external software to fix the database.
i tried importing all of the data to another newly made access file.
Try this for your expression:
Abs(Not IsNull([_characterType]))

Cannot view the SQL portion of a query in ACCESS?

I am currently working on a project of replacing our old access database queries, but on one of them I am not able to view the actual SQL View.
Does anyone know a way to force the view or to export it somehow?
Error causing problem:
The SQL statement could not be executed because it contains ambiguous outer joins.
Note that I can view the Design View without issue but when I right click on the tab and select SQL View is when I get the error.
I did attempt what #LeeMac mentioned below but same error occurs:
EDIT:
This question is not like Ambiguous Outer Joins?
The OP on that question can actually see and edit their SQL.
My issues is that I cannot see or edit the SQL as the SQL View wont open.
Try executing the following VBA code from the Immediate Window (accessible using Ctrl+G) in the VBA IDE (open the IDE using Alt+F11):
?CurrentDb.QueryDefs("YourQuery").SQL
Replace YourQuery with the name of your query.
This should print the SQL code which comprises your query - you can then analyse the SQL to determine the cause of the error.
It's odd this error would arise when merely viewing the SQL content of the query definition.
It makes me think that the query is perhaps referencing a crosstab subquery which is actually the cause of the error, but which needs to be evaluated in order for MS Access to determine the columns available when viewing the design of the query in question.
Try this:
hit ctrl-g, and from immediate window type in this:
saveastext acQuery,"Name of query","c:\test\mysql.txt"
Access ordinarily doesn't allow you to save invalid queries, so it's strange you somehow got into this situation in the first place.
If you can copy the query, you can easily get to the SQL by changing the query to a passthrough query, either through the GUI or through VBA:
Dim q As DAO.QueryDef
Set q = CurrentDb.QueryDefs!Query1
q.Connect = "ODBC;"
Debug.Print q.SQL
Passthrough queries are not validated, so you can freely read and write anything you want as SQL in it.
Note that this is irreversible when done through VBA. You can only change it back to a normal query once you made the SQL valid again. If you do it through the GUI, you can just not save it, though.
I had this problem and the issue was that i had a subquery that calculated fields but did not actually have a table in it. for example it would calculate first and last day of last month which is 2 calculated fields, then it was the first query in a series of queries that were built off it and the last one wouldnt resolve sql as original poster indicated also gave the ambiguous join message as well as query needs input table (which was that first subquery). i put a table with 1 record in it but didnt use the record and it worked.... so it just a needs a table in it.

Why do i keep getting a parameter error in my sql update?

I have been trying to use SQL with PYQT4 to update an access database with information a user has inputted into my program. I don't want to update all of the records just a specific record and a specific amount of columns (5 out of the 10 columns). however, I keep getting an error that reads:
"pyodbc.Error: ('07002', '[07002] [Microsoft][ODBC Microsoft Access
Driver] Too few parameters. Expected 6. (-3010) (SQLExecDirectW)')"
I can't seem to resolve it.
Here is my code:
SelectDatabase.execute('UPDATE Order_Table SET DateDue=(dateDueString), TimeDue=(timeDueString), PaymentType=(paymentExp), Paid=(paidExp), Customer_ID=(customerExp) WHERE OrderLine_ID=(orderlineExp)')
The values inside the brackets are variables that I have created and I am trying to call upon them, I have proof checked them multiple times, including spell checking them and I can't find a problem in that regard.
If anyone has any ideas or needs more information please let me know.
I have managed to figure out the problem. I was trying to use a variable within my SQL which once I had formatted differently worked straight away this is what I changed it to.
SelectDatabase.execute('UPDATE Order_Table SET DateDue=?, TimeDue=?, PaymentType=?, Paid=?, Customer_ID=? WHERE OrderLine_ID=?', dateDueString,timeDueString,paymentExp,paidExp,customerExp,orderlineExp)
This way by changing the values to unknowns inside the SQL procedure and referencing them in order after the edit allowed for the string values of the variables to be found and the correct columns to be edited.
Thank-you for trying to help.
Well i guess you need create your stored procedure in SQL first with all parameters and then simply call it.
Exec dbo.mYParameter 'timeDueString','paymentExp','paidExp','customerExp','orderlineExp'

Sql error on simple joins on table

Below is my simple select statement with join which gives me error
Query :
select a.*,r.* from answers a join respondents r on r.id = a.respondentid
Error:
Msg 102, Level 15, State 1, Line 2 Incorrect syntax near ' '.
I've had strange issues like this when copying and pasting queries from MS OneNote into SSMS 2014. The solution was to copy the query into notepad or outlook first and then back into SSMS. I'm sure long term my issue can be resolved by looking at the page encoding for where I store my queries.
Not sure, but probably what you can try is, close the current session and open new session and type your query manually instead of copy and paste from somewhere (try to write clean and clear query). Since, same query I was able to run
SQL Fiddle Example
==Update==
Looking at your error, which is pointing at Line 2. It seems there is some extra blank character, which probably causing this error.

Unable To Run Access Report With Column Name Which Has Special Character

I'm trying to run a report in Access that references a poorly named column: Vendor#. For those of you not familiar with Access: '#' is a reserved keyword with special meaning. I've been trying to run the report and every time I do a popup appears asking for a value for the column: in other words it keeps seeing it as a variable name. I've tried a number of variations on the name including: [Vendor#], 'Vendor#', ['Vendor#']. I tried an Alias but then I encountered the same issue in the where clause referencing the Alias. No I can't change the schema to rename the column to something more appropriate. Any help is appreciated.
Here is the query:
SELECT * FROM dbo_Vendors
WHERE ((dbo_Vendors.[Vendor#]) = [Forms]![frm_Report_Vendor]![VendorNumber])
I have just tested with a linked sql server table having a column called Vendor#. I can create a report and it runs correctly.
Can you save the query and test that the query runs? I suspect that you may have a misspelled form reference, because I have tested the whole scenario and it works for me. I do not think the report has anything to do with it.