Hello Guys,
I am trying to get a button to export the values in a listbox to excel. After extensive research on this forum and others, I came up with the code below. However, I am getting Error 13 on this line: Set rs = db.CreateQueryDef("Query1", strSQLFolder)
What am I doing wrong? :banghead:
Thank you
I am trying to get a button to export the values in a listbox to excel. After extensive research on this forum and others, I came up with the code below. However, I am getting Error 13 on this line: Set rs = db.CreateQueryDef("Query1", strSQLFolder)
What am I doing wrong? :banghead:
Code:
Private Sub cmdExportListBoxValues_Click()
Dim db As DAO.Database
Dim rs As DAO.QueryDefs
Dim strSQLFolder As String
strSQLFolder = "SELECT FolderName,Categories,ThemeName FROM QryPhotosLocationRecords WHERE FolderName='" & Me.cboFolders.Column(1) & "' ORDER BY Categories"
Set db = CurrentDb
On Error Resume Next
db.QueryDefs.Delete ("Query1")
On Error GoTo 0
Set rs = db.CreateQueryDef("Query1", strSQLFolder)
Me.ltboxLocation.RowSource = "Query1"
DoCmd.TransferSpreadsheet acImport, , , "Query1"
End Sub
Thank you