VBA SQL SELECT STATEMENT NOT PULLING ALL DATA

Larry Haydn

Board Regular
Joined
Jul 18, 2019
Messages
207
Office Version
  1. 365
Platform
  1. Windows
In my Excel VBA Application, I have the following SQL statement:

VBA Code:
Set rs = SQLConn.Execute("SELECT CustCode, CustName, ProdName, TapeDir, '', ReelLen, BoxQty, SRLblType, '', MoldingMethod, MatType, MatWidth, DimK, SID, RFID, HarmonyID, ReelType FROM PRODMAS ORDER BY CUSTCODE;")
PRODMAS.Range("A2").CopyFromRecordset rs

As you can see, there is no filter in the SQL statement.

There are 389 records in the database.

When I run the SQL Statement in SQL Server Management Studio, it pulls 389 records, as expected.
However, the same SQL statement in VBA pulls out only 349 records.
(50 records missing).

Why?
Anyone encounter similar issues?

I am using Windows 11, version 10.0.22621 Build 22621
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I ran another SQL Statement in SQL Server Management Studio on another table.
VBA Code:
SELECT * FROM SUBCONSTOCK;

It pulls out 38,805 records.
When I put it in Excel VBA, it pulls out only 48 records.

I ran another SQL Statement in SQL Server Management Studio on another table.
VBA Code:
SELECT * FROM FS1;

It pulls out 144,185 records.
When I put it in Excel VBA, it pulls out only 62,919 records.

So it seems to me that the problem is consistent, and this may be a problem in recent Windows or Office updates.
 
Last edited:
Upvote 0
Any chance it just needs delay to finish loading all the records ?
Would any of these make a difference before running the CopyFromRecordset
• Add a DoEvents Line OR
• Add a timer loop OR
• Add a loop outputting the column headings
 
Upvote 0

Forum statistics

Threads
1,215,110
Messages
6,123,146
Members
449,098
Latest member
Doanvanhieu

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