I am in the process of building a macro that will automate reporting for my team. The first part is set up to query SQL (using MS SQL Server Management Studio) based off of unique identifiers that are selected in a dialog box and then feed those results into step 2.
When building the macro, I noticed that the query returned results as expected when the list of unique identifiers is under 9,000. However, if I try to query anything over 9000 rows, the macro will run with no errors, but instead of returning results, it just shows the last active window. It basically looks like the macro has done nothing.
Since the macro works perfectly with a small dataset and there are no errors, I am a bit stumped as to how I can make it work on large datasets. Our reports are usually over 10,000 rows. Could it be my references? Any insight would be greatly appreciated. Please let me know if additional insight is needed.
EDIT:
Current code is below
Sub FilterLov1()
Dim rng As Range
Dim workrng As Range
Dim workrng1 As String
Dim today As String
Dim lastRow As Long
Dim dept As String
Dim class As String
Dim subclass As String
Dim sSQL As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim wsname As String
wsname = ActiveSheet.Name
'Set omsid list for SQL query
On Error GoTo Handler
Set workrng = Application.InputBox("Range:", Type:=8)
Application.ScreenUpdating = False
'Set rng = ActiveSheet.Range(workrng)
Dim mystring As String
mystring = RangeToString(workrng)
'Declare the SQL code here
Set cn = New ADODB.Connection
cn.Open "Provider=SQLOLEDB;Data Source=WAPRCN026A;Initial Catalog= STEP_MVIEWS;Integrated Security=SSPI"
sSQL = "select NAME, GuidID, DATASTANDARDS_PATH, PRODUCT_NAME_120, MARKETING_COPY, BULLET01, BULLET02, BULLET03, BULLET04, BULLET05, BULLET06, WORKFLOWSTATE, CHANNELSTATUS, THDONLINESTATUS from STEP_MVIEWS.dbo.[OMSID TO DATASTANDARDS] inner join STEP_MVIEWS.dbo.SCORECARD10_APPROVED on name = OMSID where [omsid] in (" & mystring & ")"
Set rs = New ADODB.Recordset
rs.Open sSQL, cn
'Sheets.Add After:=ActiveSheet
Worksheets.Add.Name = "FiltersLOVRaw"
Worksheets("FiltersLOVRaw").Cells(1, 1).CopyFromRecordset rs
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
Cells.Select
'Add Column Headers here for export file
Sheets("FiltersLOVRaw").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Cells(1, 1).value = "OMSID"
Cells(1, 2).value = "PARENT LEAF GUID"
Cells(1, 3).value = "FILE PATH"
Cells(1, 4).value = "PRODUCT NAME (120)"
Cells(1, 5).value = "MARKETING COPY (1500)"
Cells(1, 6).value = "BULLET 01"
Cells(1, 7).value = "BULLET 02"
Cells(1, 8).value = "BULLET 03"
Cells(1, 9).value = "BULLET 04"
Cells(1, 10).value = "BULLET 05"
Cells(1, 11).value = "BULLET 06"
Cells(1, 12).value = "WORKFLOW STATUS"
Cells(1, 13).value = "CHANNEL STATUS"
Cells(1, 14).value = "THD ONLINE STATUS"
Cells.Select
With ActiveSheet
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
'Sheets.Add
'ActiveSheet.Name = "Export"
'Rows(x - 1).EntireRow.Delete
'Cells.Select
Range("A1").Select
Handler:
Exit Sub
End Sub
Function RangeToString(ByVal MyRange As Range) As String
RangeToString = ""
If Not MyRange Is Nothing Then
Dim myCell As Range
For Each myCell In MyRange
RangeToString = RangeToString & ",'" & myCell.value & "'"
Next myCell
'Remove extra comma
RangeToString = Right(RangeToString, Len(RangeToString) - 1)
'RangeToString = Left(RangeToString, Len(RangeToString) - 1)
End If
End Function