Below code works fine, but my question is: how should I update my code for the case of more than 1048570? It has never happened with more than 1048570, but theoretically the maximum number of record could be almost 4 millions (very very low possibility).
Question: I only download 5 columns(Group_number, ID, FirstName, LastName, Score) of data, if the number of record > 1048570 and <=2,000,000, then download first million record in columns 1-5, and download remaining record in columns 6-11; if more than 2 millions, .... then download first millions to columns 1-5, download 2nd million to columns 6-11, and so on. .....
Is there a way to update the code to download all records if it is indeed more than 1048570? In whatever way.
The website prevents SQL code, so I add some # in the code.
Admin's note: Our system does screen for SQL injection attacks, and is overly aggressive in doing so. A workaround is to pick a letter in the word and set the color to black. It will still look the same, but the extra color tags will change the string so it will not be screened. I've done that for you here for readability. --6StringJazzer
Post on another site: https://www.reddit.com/r/vba/comment...xcel_sheet_if/
Set RecordCountRs = CreateObject("ADODB.Recordset") RecordCountQuery = "Select COUNT(*) From Table_ABC WHERE Group_number = " & InputGroupNumber 'InputGroupNumber is integer RecordCountRs.Open RecordCountQuery, ConnectionString WB.Sheets("Summary").Cells(1, 2).Value = RecordCountRs.Fields(0).Value Set RecordCountRs = Nothing If WB.Sheets("Summary").Cells(1, 2).Value <= 1048570 Then Set RecordDownloadRs = CreateObject("ADODB.Recordset") RecordDownloadQuery = "Select Group_number, ID, FirstName, LastName, Score From Table_ABC Where Group_number = " & InputGroupNumber RecordDownloadRs.Open RecordDownloadQuery, ConnectionString j = 0 For Each RecorddownloadField In RecordDownloadRs.Fields WB.Sheets("Download Sheet").Cells(1, 1).Offset(, j) = RecorddownloadField.Name j = j + 1 Next WB.Sheets("Download Sheet").Cells(2, 1).CopyFromRecordset RecordDownloadRs Set RecordDownloadRs = Nothing Else Msgbox "More than 1048570 records. The program does not download any records." End If
Bookmarks