simple SELECT query to .mdb still fails :(

fedefring

New Member
Joined
Aug 27, 2018
Messages
8
Hi guys,
nice to meet you All!


I am struggling with Excel, trying to get data from an .mdb Access old db,
via SQL query "only".


I mean "only", cause I am able to get what I need by "looping" through records without
errors, but I assume using SQL is extremely better!


So, code you will see below, is ok in order to get connected to the db and
I can easily get recordset content by looping,
but I did a lot of tentatives with queries you will see and
in no one case (you see only two here) I was able to run correctly the query
cause I always get "query sintax error" when executed.


Where is my error ?


To be clear in advance, I cannot use ADO or DAO to connect, cause this is a very old
db and also a very old xls with dozens of macros with the same kind
of connection method you see below.


Thank you in advance,
Fred!


------------------
Private Function aggiorna_comm(stringa_connessione, valuex) As Boolean


On Error GoTo Err_aggiorna_comm


Dim db_destination As Database
Dim rs_destination As Recordset


Set db_destination = OpenDatabase(stringa_connessione)
Set rs_destination = db_destination.OpenRecordset(tabx)


1)
strQry = "SELECT * FROM '" & tabx & "' WHERE '" & fieldx & "' = '" & valuex & "'"
2)
strQry = "SELECT * FROM "&tabx&" WHERE "&fieldx&" = " & valuex & "' "


db_destination.Execute strQry


test = rs_destination!idComm


Err_aggiorna_comm_exit:
rs_destination.Close
Set rs_destination = Nothing


db_destination.Close
Set db_destination = Nothing
Exit Function


Err_aggiorna_comm:
MsgBox Error$
Resume Err_aggiorna_comm_exit


End Function
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
How can I mark this topic as Solved ?
You just did. That is all you have to do.
We don't actually "close" out threads, as many times, someone will post an alternative solution (after it is has been "solved"), and sometimes, the alternative is even a better solution.
So we do not want to discourage that behavior.

But letting us know it works and thanking the contributors is always appreciated, so thank you for doing that!:)
 
Upvote 0
You just did. That is all you have to do.
We don't actually "close" out threads, as many times, someone will post an alternative solution (after it is has been "solved"), and sometimes, the alternative is even a better solution.
So we do not want to discourage that behavior.

Wow, flexible mindset! So see you Joe, bye :)
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top