fastpants
New Member
- Joined
- Jun 22, 2007
- Messages
- 33
Hello
I have written the following code, however my code crashed out when it gets to the bolded section; when it tries to actrually run the query. It works on normal queries its just the corsstab queries where it has problems. Can someone help please?
I have written the following code, however my code crashed out when it gets to the bolded section; when it tries to actrually run the query. It works on normal queries its just the corsstab queries where it has problems. Can someone help please?
Code:
Sub InboundLeads()
Dim cat As ADOX.Catalog
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Dim i As Integer
Dim strPath As String
Dim QryOne As String
QryOne = "1b Query_InboundLeads_Crosstab"
strPath = "\\network1\Daily Tracker\Database V2.mdb"
Set cat = New ADOX.Catalog
cat.ActiveConnection = "provider=microsoft.jet.oledb.4.0;" & _
"data source=" & strPath
<b>Set cmd = cat.Views(QryOne).Command</b>
Set rst = cmd.Execute
Sheets(2).Select
For i = 0 To rst.Fields.Count - 1
Cells(1, i + 1).Value = rst.Fields(i).Name
Next
With ActiveSheet
.Range("A2").CopyFromRecordset rst
.Range(Cells(1, 1), _
Cells(1, rst.Fields.Count)).Font.Bold = True
.Range("A1").Select
End With
Selection.CurrentRegion.Columns.AutoFit
rst.Close
Set cmd = Nothing
Set cat = Nothing
End Sub