Export query to Excel

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Export query to Excel

Post by Michael Abrams »

Query name = OPEN ISSUES FOR REPS
Target - S drive - Folder - HMO ISSUES - LETTERS SENT & RESPONSES

Code: Select all

Dim strFileName As String

strFileName = "S:\HMO ISSUES - LETTERS SENT & RESPONSES”

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "OPEN ISSUES FOR REPS", strFileName, True
Receiving message:
Screenshot 2023-05-18 073653.png
Folder is not open and I have FULL permissions to view & write.

Can you see what needs to be tweaked?

Thank you for all you do :grin:
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Export query to Excel

Post by HansV »

The value of strFileName is a folder path, you forgot to include the file name. Moreover, you have curly quotes at the end of the string (but perhaps that's just in this thread).
Try

Code: Select all

strFileName = "S:\HMO ISSUES - LETTERS SENT & RESPONSES\Export.xlsx"
or

Code: Select all

strFileName = "S:\HMO ISSUES - LETTERS SENT & RESPONSES\OPEN ISSUES FOR REPS.xlsx"
Best wishes,
Hans

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Re: Export query to Excel

Post by Michael Abrams »

Thak you HansV. Works fine now.

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Re: Export query to Excel

Post by Michael Abrams »

I know I have done this before, but after 20 years, I can't remember what project it was.
2 queries:
OPEN ISSUES FOR BAY CLIENTS
OPEN ISSUES FOR VALLEY CLIENTS
Both have the same "where" clause: WHERE (((ISSUES.DATE_ISSUE_OPENED)<[ENTER DATE MM/DD/YYYY]))

Command button on form REPORT MENU code:

Code: Select all

Private Sub cmdLeaderReview_Click()

Dim strFileName1 As String
Dim strFileName2 As String

strFileName1 = "S:\HMO ISSUES - LETTERS SENT & RESPONSES\SUPV ISSUES\OPEN ISSUES FOR BAY CLIENTS.xlsx"

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "OPEN ISSUES FOR BAY CLIENTS", strFileName1, True

strFileName2 = "S:\HMO ISSUES - LETTERS SENT & RESPONSES\SUPV ISSUES\OPEN ISSUES FOR VALLEY CLIENTS.xlsx"

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "OPEN ISSUES FOR VALLEY CLIENTS", strFileName2, True

MsgBox "SUPERVISOR REVIEW ISSUES HAVE BEEN EXPORTED", vbInformation

DoCmd.Close acForm, "REPORT MENU"

End Sub
The parameter box does pop up twice (once for each query). I believe I need to fix the where clause in the 2 queries but cannot find where I have done this before.

Thank you in advance.

Michael

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Export query to Excel

Post by HansV »

Instead of a parameter prompt [ENTER DATE MM/DD/YYYY], place a text box on the form.

Name: txtDate
Format: mm/dd/yyyy
Caption of associated label: Enter date

Change the WHERE clause of both queries to

WHERE ISSUES.DATE_ISSUE_OPENED<[Forms]![REPORT MENU]![txtDate]
Best wishes,
Hans

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Re: Export query to Excel

Post by Michael Abrams »

That's IT ! Thank you again HansV