Developing environment is VBA (AutoCAD)
I have Set of values stored in that array function BomLine(iCountItem).PartNo
which I want to further use it fetch data into Excel through a specific SQL query.
Function gets its value from an AutoCAD drawing and stores the value into; that part is successful, but it's not fetching data into excel, maybe I am not correctly using the For Each
loop?
This is what I am doing:
Dim OExcel As Object
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim ConnectionString As String
Dim StrQuery As String
Dim xyz as Variant
For x = 0 To UBound(DwgBlocks(i).AttributeName)
Select Case DwgBlocks(i).AttributeName(x)
Case OldDwgFmt.BOMPartNo
BomLine(iCountItem).PartNo = DwgBlocks(i).AttributeVal(x)
End Select
Next x
Exit For
Set OExcel = CreateObject("Excel.Application")
If OExcel Is Nothing Then
Exit Sub
End If
With OExcel
.Visible = True
.Workbooks.Add
.SheetsInNewWorkbook = 1
End With
With worksheet
ConnectionString = "Provider=SQLOLEDB.1;Password=***;Persist Security Info=True;User ID=***;Data Source=***\***;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Use Encryption for Data=False;Tag with column collation when possible=False;Initial Catalog=***"
cnn.Open ConnectionString
cnn.CommandTimeout = 900
List = "BomLine(iCountItem).PartNo"
For Each xyz in List
StrQuery = "SELECT * FROM [MY_Table] WHERE [MY_Column]='xyz'"
rst.Open StrQuery, cnn
Set worksheet = OExcel.Worksheets(1).cells(1, 1).CopyFromRecordset rst
Exit For
Next xyz
End With