Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Code No Longer Works
John Valencic 
     
13 months ago
I have some code opn a button that runs a Query and outputs the result to an Excel spreadsheet, and all of the sudden it stopped working and am unable to figure out why. Maybe someone can help me out.
This is my code:
Private Sub ExportToExcel2_Click()
        DoCmd.OutputTo acOutputQuery, "Email_List_Q", acFormatXLSX, "C:\Users\John\Documents\Sportsmens_Club_SSA\SSA_Digital_Copies\Excel_Email_Lists\Excel_Email_List" & "_" & Format(Now(), "mmddyyyy_hhnn") & ".xlsx", True
        Application.FollowHyperlink "C:\Users\JohnV\Documents\Sportsmens_Club_SSA\SSA_Digital_Copies\Excel_Email_Lists\"

End Sub

Thanks in advance
Kevin Robertson  @Reply  
          
13 months ago
The paths are different.
The first path say John, but the second path says JohnV.
I would store the path in a variable so you only need to type it once.
This will help prevent these kinds of mistakes.

Details    Dim Filename As String
    
    Filename = "C:\Users\John\Documents\Sportsmens_Club_SSA\SSA_Digital_Copies\Excel_Email_Lists\Excel_Email_List" & "_" & Format(Now(), "mmddyyyy_hhnn") & ".xlsx"
    
    DoCmd.OutputTo acOutputQuery, "Email_List_Q", acFormatXLSX, Filename, True
    Application.FollowHyperlink Filename
Sami Shamma  @Reply  
             
13 months ago
What does not work?
Did you try to execute each command separately? for example run "Email_List_Q", then output to simple file name
then put "C:\Users\John\Documents\Sportsmens_Club_SSA\SSA_Digital_Copies\Excel_Email_Lists\Excel_Email_List" & "_" & Format(Now(), "mmddyyyy_hhnn") & ".xlsx"

in a variavle and msgbox it.
John Valencic OP  @Reply  
     
13 months ago
Now I have to say, I feel like such a fool. After changing the code many times, completely deleting it, pasting the code from a backup that was known to work, I forgot to go into the property sheet for the command button and select "Event Procedure" for the "On Click" event. Once I did that, everything worked as it should. My apologies, and thanks for your time and expertise.....

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/7/2026 12:54:01 AM. PLT: 1s