By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,600 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,600 IT Pros & Developers. It's quick & easy.

code after "Docmd.OutputTo.." ignored?

P: 54
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:\FullTimetable.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!

Expand|Select|Wrap|Line Numbers
  1. If [Forms]![ReportsMenu]![InvigTTBySchool].Value = True Then
  2. ChoiceOne = True
  3. MyChoiceOne = "FullTimetablebyFaculty"
  4. MyReportOne = "FullTimetable"
  5.     DoCmd.OutputTo acReport, MyChoiceOne, "SnapshotFormat(*.snp)", "c:\" & MyReportOne & ".snp", False, ""
  6. MsgBox "test"
  7. Else
Thanks!

Allen
Dec 23 '09 #1

✓ answered by missinglinq

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:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acReport, 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)>

Share this Question
Share on Google+
16 Replies


Expert 100+
P: 1,287
Do any of your functions have error handling code?
Dec 23 '09 #2

P: 54
at the top of the function I have:

Expand|Select|Wrap|Line Numbers
  1. Function ExSnap1()
  2. On Error GoTo Macro1_Err
  3.  
and at the bottom I have:

Expand|Select|Wrap|Line Numbers
  1. Macro1_Err:
  2.     MsgBox Error$
  3.     Resume Macro1_Exit
  4. End Function
  5.  
apart from that there is no other error handling. PS Thanks for your quick response!!
Dec 23 '09 #3

Expert 100+
P: 1,287
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?
Dec 23 '09 #4

Megalog
Expert 100+
P: 378
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.
Dec 23 '09 #5

P: 54
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!!
Dec 23 '09 #6

P: 54
just done the step into and it went straight from the DoCmd Output To... to the error handler. No explanation why though!!
Dec 23 '09 #7

Megalog
Expert 100+
P: 378
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.
Dec 23 '09 #8

Megalog
Expert 100+
P: 378
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.
Dec 23 '09 #9

P: 54
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!
Dec 24 '09 #10

NeoPa
Expert Mod 15k+
P: 31,402
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.
Dec 24 '09 #11

P: 54
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
Dec 25 '09 #12

missinglinq
Expert 2.5K+
P: 3,532
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:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acReport, 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)>
Dec 26 '09 #13

P: 54
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.
Jan 4 '10 #14

NeoPa
Expert Mod 15k+
P: 31,402
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.
Jan 4 '10 #15

P: 54
Thanks NeoPa they are very useful!
Jan 4 '10 #16

NeoPa
Expert Mod 15k+
P: 31,402
Always a pleasure G_Diddy :)
Jan 4 '10 #17

Post your reply

Sign in to post your reply or Sign up for a free account.