Macro Record MS Query - Redundant code?

bs0d

Well-known Member
Joined
Dec 29, 2006
Messages
622
In Excel 2013, If I record a macro for an MS Query to an Access database, the corresponding VBA code appears to be redundant, showing the query syntax twice. ONe has a .CommandType = xlCmdSql, the other has a .CommandType = 0.

In any event, if you try to run the macro, it doesn't work. If you move the ODBC query block with .commandType = xlCmdSQL to the top, then I get an error: Type Mismatch in the SQL code. However, while recording the macro, it is a successful query.

Can someone show me an example Excel 2013 MS Query code for an MS Access Database as a guide, vs. the Excel macro recorder that doesn't seem to be working for me?

I
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
[SOLVED]

I got this to work by removing the Array() from my SQL query string. Excel added this through the macro recording.
 
Upvote 0
Also, Excel creates nearly a duplicate query string when you edit the properties after creating the query in MS query.
 
Upvote 0

Forum statistics

Threads
1,223,718
Messages
6,174,082
Members
452,542
Latest member
Bricklin

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