Hi,
I have been searching on the net for the past few hours and no success so any help will be appriciated. So far i have a query "FullAreaExport" this uses a criteria for which is fetches from a combo box on my form. when i run the query from the form it works fine but what i want to do is have it export to excel. The export code i have and it works on other queries without the criteria. Please can someone assist me..... this is my code so far:
I have been searching on the net for the past few hours and no success so any help will be appriciated. So far i have a query "FullAreaExport" this uses a criteria for which is fetches from a combo box on my form. when i run the query from the form it works fine but what i want to do is have it export to excel. The export code i have and it works on other queries without the criteria. Please can someone assist me..... this is my code so far:
Code:
Private Sub Command293_Click()
On Error Resume Next
strQueryName = "FullAreaExport"
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWorkbook = xlApp.Workbooks.Add
Set objRST = Application.CurrentDb.OpenRecordset(strQueryName)
Set xlSheet = xlWorkbook.Sheets(1)
For lvlColumn = 0 To objRST.Fields.Count - 1
xlSheet.Cells(1, lvlColumn + 1).Value = objRST.Fields(lvlColumn).Name
Next
xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(1, objRST.Fields.Count)).Font.Bold = True
With xlSheet
.Range("A2").CopyFromRecordset objRST
.Name = Left(strQueryName, 31)
.Columns("A:AZ").EntireColumn.Autofit
End With
Set xlSheet = Nothing
Set xlWorkbook = Nothing
Set xlApp = Nothing
End Sub