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
 

Some videos you may like

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

bs0d

Well-known Member
Joined
Dec 29, 2006
Messages
622
[SOLVED]

I got this to work by removing the Array() from my SQL query string. Excel added this through the macro recording.
 

bs0d

Well-known Member
Joined
Dec 29, 2006
Messages
622
Also, Excel creates nearly a duplicate query string when you edit the properties after creating the query in MS query.
 

Watch MrExcel Video

Forum statistics

Threads
1,099,044
Messages
5,466,213
Members
406,473
Latest member
Dunno123

This Week's Hot Topics

Top