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 
Access Developer lesson 16 1
Dalal Ajassim 
   
5 years ago
I have gone through your VBA lessons and downloaded lessons 16 and 17.
I tried to apply my new knowledge to my access form but it seems I'm missing something.
I want to extract individual pdfs reports for each of our employees.
i have simplified the problem that i need to recode your lesson based on a query with parameters.
this is my code:


Private Sub Command2_Click()
        
        Dim dbs As DAO.Database
        Dim qdf As DAO.QueryDef
        Dim prm As DAO.Parameter
        Dim rst As DAO.Recordset

    Set dbs = CurrentDb
    Set qdf = dbs.QueryDefs("PDFExtracting")
    qdf.Parameters("Forms!MainMenu!EmployeeID") = KOC#

  ' Open recordset on the query

    Set rst = qdf.OpenRecordset
    
   While Not rs.EOF
  
   Forms!MainMenu!EmployeeID = rs!KOC#
        ' forms!MainMenu.refresh
        
         DoCmd.OutputTo acOutputReport, "PDP", acFormatPDF, _
            "C:\Users\Mohammaed Al-Hamad\Desktop\PDP\Personal tracker' & rs!KOC# & '.pdf"
            
        rs.MoveNext
        
    Wend
    
     rst.Close
     qdf.Close
     dbs.Close
  
    Set qdf = Nothing
    Set rs = Nothing
    Set db = Nothing

End Sub


but still an error message is shown .
Would you be kind to show me the error that I'm committing?
it would be a great help to me.

regards,
Dalal ALjassim
Adam Schwanz  @Reply  
           
5 years ago
What error are you receiving and what does debug show?
William Dowler  @Reply  
      
5 years ago
Your recordset is defined as rst but in some places you are referring to it as rs.
Scott Axton  @Reply  
        
5 years ago
Dalal -
One thing I'm seeing in the code above is in the DIM statement you use "rst" as the variable.
Further down you use ** RS **  as in While Not rs.EOF and rs.MoveNext and Set rs = Nothing

If this is the actual copy of the code in your db that could be throwing errors.

I recommend putting "Option Explicit" in your code 2nd line down at the very top under the "Option Compare Database".
That will catch instances of variables mistyped or not declared.
Try fixing that and see if it helps.

Scott
Scott Axton  @Reply  
        
5 years ago
Another.  You are using the
     Set rst = qdf.OpenRecordset

But you didn't tell access which recordset to open.  OpenRecordset requires a parameter  

     Set rst = qdf.OpenRecordset ("**Table, Query, or SQL statement Here **")
Richard Rost  @Reply  
           
5 years ago
I see a lot of errors in your code. In addition to the points that my very keen students have pointed out, you've got some rookie mistakes such as using both " and ' when working with the same string. This is what happens when you "jump in" in the middle of a course series without having taken all of the pre-requisite courses. What is KOC#? You don't need a QueryDef, you should use an SQL statement, like I teach. You don't need to specify DAO unless you're also working with ADO in the same database. I can tell you've pieced this code together from various Google searches. That's OK. It's a good way to learn, but you've hobbled together something that's inconsistent.
John Davy  @Reply  
          
5 years ago
Hi, I am not sure of your error, but take note that you use rst in most places but you still have  Set rs = Nothing

HTH

John

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/6/2026 1:20:12 PM. PLT: 0s