Results 1 to 8 of 8
  1. #1
    damo1995 is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    9

    Runing Moduels from Macro's - Access 2003

    Would somebody be able to help me please,

    I am attempting to run a piece of code that has been made in a modual with a public class and want to run it via a macro on a swichboard, but i have tryed the Runcode function but i cannot seem to get it to work this error keeps poping up every time i attempt to run it,




    The code i am trying to run is this,
    Code:
    ' Gives the script a name
    Public Function customer()
        'Tell's the script if there is an error to go to the ErrorHandle function
        On Error GoTo ErrorHandle
        
        'Opens the report for customers
        DoCmd.OpenReport "Customer Records", acViewPreview
        
        'Does the equivalent of File > Print
        DoCmd.RunCommand acCmdPrint
        
        ' Close's the report after print job is sent to printer.
        DoCmd.Close acReport
        
    'Threads the error handler
    ErrorHandle:
        
        ' Print's a dialox box if an error occurs that says there was an error and to try again.
            MsgBox "A Error Occurred whilst trying to print please try again. "
            'Quits the script
            Exit Function
        'Quit's the IF function above for ErrorHandle
        End If
    'Ends the script and then wates to be run again from the switchboard
    End Function

    And this is the error,
    Thanks

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    why is there a condition in the macro??

    also, I doubt you need this:
    Code:
    DoCmd.Close acReport
    first of all, you spec'd a report but didn't name it with the next arg. that might be a problem. also, I believe 99%, that using that command with no arguments closes the object with focus. but to be safe, write:
    Code:
    docmd.close acreport, "reportname"
    ALSO...are you sure your vbe is set to handle errors when handlers are present? there is a setting to break on all errors, regardless if handlers are written into procedures or not.

  3. #3
    damo1995 is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    9
    Quote Originally Posted by ajetrumpet View Post
    why is there a condition in the macro??

    also, I doubt you need this:
    Code:
    DoCmd.Close acReport
    first of all, you spec'd a report but didn't name it with the next arg. that might be a problem. also, I believe 99%, that using that command with no arguments closes the object with focus. but to be safe, write:
    Code:
    docmd.close acreport, "reportname"
    ALSO...are you sure your vbe is set to handle errors when handlers are present? there is a setting to break on all errors, regardless if handlers are written into procedures or not.
    To be honist wih you i dont know if the vbe is set to handle errors, my main goal was to attempt to print a report with a print dialox box from the swichboard and thats were this code came in, my teacher gave me it as its part of my GCSE IT work but when we hit this we both were at a loss, so i came here i shall attempt to add in
    Code:
    docmd.close acreport, "Customer Report"
    and see if that helps at all other wise i shall come back here and ask for more help on this isue if that is ok, also how would i check that my vba is setup for error handling ?


    Thanks

    Damo

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    error handling options: tools > options > general tab > error trapping section

    also, consider the fact that you can open a report in NORMAL view, which prints to your default printer automatically. no need for 3 lines of code, and/or a print command.

  5. #5
    damo1995 is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    9
    Quote Originally Posted by ajetrumpet View Post
    error handling options: tools > options > general tab > error trapping section

    also, consider the fact that you can open a report in NORMAL view, which prints to your default printer automatically. no need for 3 lines of code, and/or a print command.
    My problem with that is i need it to show the print dialox box and not just use the default printer and im not sure if this is posible or not with the printreport macro function,

    Thanks

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    you need to choose a printer to send it too?? then yes, I would think you'd need to send the keys, OR use the print command, as I believe that's the same as pushing a menu option. it always brings up the print dialog too, doesn't it?

  7. #7
    damo1995 is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    9
    well the way i did have it setup was to just use the printreport function but that was auto printing to the default printer which is not what i want, then i attempted to use the openreport as first command print as second closereport as third but again it just kept auto defaulting to the default printer and not allowing me to choose what i wanted to, so this is why i attempted to use a VBA to attempt to print it off with hope that it would allow the print dialox box to open, but so far not had no luck because of error's

  8. #8
    damo1995 is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    9
    Ok i tried what was said above and it still failed to load the VBA so i think i may give up on this unless you have any other ideas on how i can print it and at the same time bring up the print dialox box.

    Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. code changes from access 2003 to access 2007
    By daversb in forum Programming
    Replies: 1
    Last Post: 11-30-2010, 05:32 PM
  2. Convert access 2003 to access 2010
    By Vera in forum Access
    Replies: 3
    Last Post: 07-16-2010, 11:01 AM
  3. Replies: 0
    Last Post: 07-16-2010, 09:06 AM
  4. Replies: 6
    Last Post: 12-01-2009, 11:59 AM
  5. Replies: 1
    Last Post: 09-06-2006, 11:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums