Msgbox code stops working in report

  • Thread starter Thread starter HelenM
  • Start date Start date
H

HelenM

I'm using a report based on a parameter query, and I'm trying to bring up a
message box when the report is closed asking if the user wants to 'search
again'. I don't actually know how to use VBA but I've been making it up from
the help menu and the tips on these websites, but I've managed to create the
message box, and when I run the code just in Visual Basic, it works fine.
However, when I then try to use it as the 'onclose' property for the report,
the message box comes up but none of the options do anything, and I don't
know why! It's probably me being really dim but I don't really know anything
about Visual Basic so I can't fix it!
 
Hi HelenM,

please post the non working code so we can see what you wrote and give you
an advice on what could be wrong.

Cheers Paolo
 
The code is as follows and then I'm just setting the OnClose property to =
OnClose()
Thanks for messagin back

Function OnClose()
Select Case MsgBox("Would you like to search again?", vbQuestion +
vbYesNoCancel, "Search Again?")
Case vbYes
DoCmd.RunMacro ("Search Again")
Case vbNo
'Do nothing
Case vbCancel
DoCmd.CancelEvent
End Select
End Function
 
Hi HelenM,

your function is correct. To call it, instead of setting the OnClose
property to =
OnClose(), in this way Access search a macro, delete everything is written
near the onclose property of the report, click the box with the three dots on
the right of the on close row and select code builder and just write onclose
(this is to call your function on the on close event) between Private Sub
Report_Close() and end sub. Close the vba window, close the report and save
the changes and everything will work correctly.

HTH Paolo
 
Thanks for replying, I did everything you said but that is bringing up the
error message:
Compile error: Invalid use of property.
Thanks
 
Well HelenM, try to call the function on_close or something like that 'cause
onclose could be a reserved word.

Regards Paolo
 
Thanks but that's just put me back where I started, the message box pops up
but none of the options do anything except close the box. When I run the code
in VB it works fine but not when running the report.
 
Where did you write your function? You have to write it in a module exacly as
you posted or in the on close event of your report in this way:

Select Case MsgBox("Would you like to search again?", vbQuestion +
vbYesNoCancel, "Search Again?")
Case vbYes
DoCmd.RunMacro ("Search Again")
Case vbNo
MsgBox "do nothing"
Case vbCancel
DoCmd.CancelEvent
End Select

If you use it in a module did you rename it. As I said you cannot name it
onclose because it's a reserved word.

I'm asking all those question because I tried on my pc and everything works
fine.

Paolo
 
I just redid the whole thing, just to check and it's still not working. I
don't get it lol, coz I know it should work!!! Thanks for trying anyway,
maybe my pc is just not right in some way!
 
Back
Top