code after "Docmd.OutputTo.." ignored?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • g diddy
    New Member
    • Sep 2009
    • 54

    code after "Docmd.OutputTo.." ignored?

    Hi, I have used the Docmd.outputto function in various places in my code but for some reason all code that comes afterwards, even msgbox doesn't show. I was just wondering if there is anything that could be causing this. For example in the snippet below the docmd command brings up a box saying that it is outputting the file to c:\FullTimetabl e.snp but no msgbox appears saying "test". I have about 6 or so if statements with the same problem and i'm hoping it is nothing major. Your help is greatly appreciated!

    Code:
    If [Forms]![ReportsMenu]![InvigTTBySchool].Value = True Then
    ChoiceOne = True
    MyChoiceOne = "FullTimetablebyFaculty"
    MyReportOne = "FullTimetable"
        DoCmd.OutputTo acReport, MyChoiceOne, "SnapshotFormat(*.snp)", "c:\" & MyReportOne & ".snp", False, ""
    MsgBox "test"
    Else
    Thanks!

    Allen
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    Do any of your functions have error handling code?

    Comment

    • g diddy
      New Member
      • Sep 2009
      • 54

      #3
      at the top of the function I have:

      Code:
      Function ExSnap1()
      On Error GoTo Macro1_Err
      and at the bottom I have:

      Code:
      Macro1_Err:
          MsgBox Error$
          Resume Macro1_Exit
      End Function
      apart from that there is no other error handling. PS Thanks for your quick response!!

      Comment

      • ChipR
        Recognized Expert Top Contributor
        • Jul 2008
        • 1289

        #4
        Very strange. Is the output file actually created? Does this happen with multiple reports? And, what happens if you stop on the DoCmd.OutputTo in debug and step forward?

        Comment

        • Megalog
          Recognized Expert Contributor
          • Sep 2007
          • 378

          #5
          I've had this happen before. I think the problem was the report I was trying to output didnt have any records, so it would just drop the whole subroutine right at the DoCmd.OutputTo line.

          Edit: Nevermind, I just tried recreating that scenario and the report outputs either way. If I remember exactly what the answer was I'll drop an update.

          Comment

          • g diddy
            New Member
            • Sep 2009
            • 54

            #6
            that's another thing ChipR; it says the file has been created but it does not show up in the C drive. Also sometimes I get an error message saying that there is not enough free disk space to save it. I think this may be related in some way! However I cannot see why it isn't working - it used to work and the code for outputting it to a file is exactly the same. I'd hate to do it as the code is very long, but would pasting the entire code here be able to give you more context? I thought about that Megalog and i've just opened one of the reports and the information was there. However I do agree, I think that it may be just dropping the whole subroutine as after that line as even Msgbox "Test" doesn't work!!

            Comment

            • g diddy
              New Member
              • Sep 2009
              • 54

              #7
              just done the step into and it went straight from the DoCmd Output To... to the error handler. No explanation why though!!

              Comment

              • Megalog
                Recognized Expert Contributor
                • Sep 2007
                • 378

                #8
                I've seen the out of memory error happen when you try to feed an illegal filename/filepath into the command line. Although the filename you're using is about as simple as it can get. Are you on a work machine where perhaps your local policy is preventing files from writing to the root of your C: drive? Try hardcoding the output filepath/filename to your desktop location.

                Comment

                • Megalog
                  Recognized Expert Contributor
                  • Sep 2007
                  • 378

                  #9
                  This can also happen if the file you're trying to write to is already open by another process, or has been marked as read-only.

                  Comment

                  • g diddy
                    New Member
                    • Sep 2009
                    • 54

                    #10
                    yes it is a work machine, im not sure what the local policy with it is though so that may be the case, however i'm sure it used to work. How would I go about hard coding it to the desktop location? like say my personal drive was Y would I just simply need to change the C:\ to Y:\? As far as I know it isn't opened by another process. Later on in the code I convert from snp to pdf but as it doesn't seem to be outputting at all it isn't even getting anywhere near that stage so I don't reckon that is the problem... touch wood!

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32633

                      #11
                      I guess you can see that this is the answer to your question though yes? The subsequent code is never executed as the line causes an error, from which your error handling code simply returns execution to the end of the subroutine.

                      Some further information could be displayed from the contents of the Err object in your Error Handling routine should you wish.

                      Comment

                      • g diddy
                        New Member
                        • Sep 2009
                        • 54

                        #12
                        thanks for all your help and advice guys. i'm off work til the 4th of jan but when I get back i'm going to try a few things and see how it goes; using everything you've said to guide me. I'll let you know how it goes. thanks for your help

                        Comment

                        • missinglinq
                          Recognized Expert Specialist
                          • Nov 2006
                          • 3533

                          #13
                          As NeoPa has pointed out, your code is causing an error, which drops you to the error handler, thus bypassing the message box. The problem is here:
                          Code:
                          DoCmd.OutputTo [B]acReport[/B], MyChoiceOne, "SnapshotFormat(*.snp)", "c:\" & MyReportOne & ".snp", False, ""
                          Instead of acReport it should be acOutputReport, which should be popping up as a choice from Intellisense.

                          Linq ;0)>

                          Comment

                          • g diddy
                            New Member
                            • Sep 2009
                            • 54

                            #14
                            Thanks very much for that correction missinglinq, the error message now no longer appears. For some reason though, when I step through the code it still gets to this line and then shows the message box saying that it is outputting to file but then the code stops and when I step through again it starts at the beginning of the code. There are no error messages and everything after this line is ignored, even msgbox, and also the file is not created. I'm going to try a few things over the next few days but if anyone has any ideas that would be great. Thanks for all your time!

                            Edit: I changed the location from C to U (my personal drive at work) and the file outputted so the output problem may be something to do with access privelages. I've managed to get it working correctly now. Thanks very much for all your time and effort.

                            Comment

                            • NeoPa
                              Recognized Expert Moderator MVP
                              • Oct 2006
                              • 32633

                              #15
                              That's good to hear, but it's always better to understand what's going on - especially when things don't work as required.

                              I sometimes find that the Error Trapping setting in the VBE can cause issues for people trying to debug. Debugging in VBA is a useful resource when thinking about debugging, but more specifically, Debugging in VBA - 3) General Tips discusses the settings that should be selected for most effective debugging.

                              Comment

                              Working...