Link to home
Start Free TrialLog in
Avatar of pcsettles
pcsettlesFlag for United States of America

asked on

Make MsgBox non modal?

I want to open a report in preview mode via a button on a form, give the user the chance to print the report or not, then open a MsgBox that asks if the report printed ok (printer might be down, wrong paper, etc).  If the answer is 'Yes', then I do an update query on a table.  Following is my code so far:

  stDocName = "rptLetterConfirmation"
  DoCmd.OpenReport stDocName, acPreview, , , acDialog

  Msg = "Confirmation Letters Print Correctly?"    ' Define message.
  Style = vbYesNo + vbDefaultButton2    ' Define buttons.
  Title = "Confirmation Letters"    ' Define title.

  Response = MsgBox(Msg, Style, Title)
  If Response = vbYes Then    ' User chose Yes
    DoCmd.Close
   
    'SQL to fill TchLtr with Date()
    SqlStr = "UPDATE tblOrders SET tblOrders.TchLtr = Date() " & _
              "WHERE (((tblOrders.TchLtr) Is Null));"
    DoCmd.RunSQL SqlStr

The problem is that when the report preview becomes modal the user can't get to a print command. If I make the report preview non-modal, the MsgBox appears and seems to always be modal.   Hence, the user can't get back to the preview report to print it without answering the MsgBox first.  If I could make the MsgBox non-modal, I think I'd be ok.
ASKER CERTIFIED SOLUTION
Avatar of jjafferr
jjafferr
Flag of Oman image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OR

On Exit of the Report, make a msgbox appear with your request, and make your code in a module, so it be executed and free the Report from memory.

jaffer
Avatar of Patrick Matthews
I'm pretty sure MsgBox is always modal; looking at the documentation, your only choice is
between application modal and system modal.

However, you can use an Access form, which can be modeless, to poll the user.
The message box will either be Application Modal or System Modal ... the only two options, unfortunately.

mx
Avatar of pcsettles

ASKER

To jjaffer: Ok, I didn't think about doing your first suggestion.  I can do that and it should work fine.  However, I don't fully understand your second suggestion.  I can't figure out how to Exit the Report, and 'then' have the MsgBox appear.  Are you saying that if the MsgBox code is in a module that is called just after the OpenReport, it won't appear until after the Report is Exited?
Hi pcsettles
>Ok, I didn't think about doing your first suggestion
this is where we try to help,
but why did you give me a B grade :(
the solution fits your requirment, and you were happy with it, but I know there is No magic or glory in it!!!

>I don't fully understand your second suggestion
my mistake, Reports don't have "On Exit", it should be "On Close".
looking at your requirement,
you don't need to have the Report open, while the msgbox is open too,
I would do it in the following way:
Open the Report in preview mode to allow the user to print or not,
place your above code as a PUBLIC SUB Printed() in a module,
"on close" of the Report have a code to quit the Repeort, then to run the SUB Printed,
so now, the Report is closed, and you have your normal msgbox,
if the user clicks Yes (remove the docmd.close), then run your SQL,
if the user clicks No, then you can either print the Report by opening it in a normal mode, OR open the Report Again in preview mode, and go through this cycle again.


jaffer
Hi jjaffer:
Thanks for your continued interest in my question.  I already took care of the issue by following your first suggestion.  I will attempt your latest comment when I get time to see if it works any better and for my own instruction.  Thanks again for the suggestions.
pcsettles