DoCmd.Close (1 Viewer)

tbennekik

New member
Local time
Today, 02:48
Joined
Jan 21, 2021
Messages
4
I am using Office 365

I want te close a report in VBA and use the folowing:

Private Sub Report_Close()
DoCmd.Close acReport, "ROpzoeken Paswoorden"
DoCmd.OpenForm "Menu", acNormal
End Sub

The Close action always gives an error.
I get error 2501 with the info: "action Close is canceled.

Does someone have a solution?
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:48
Joined
Sep 21, 2011
Messages
14,465
Is that code in report "ROpzoeken Paswoorden" ?
 

Ranman256

Well-known member
Local time
Yesterday, 20:48
Joined
Apr 9, 2015
Messages
4,337
when you close rpt "RO" , you are telling it to close "RO" again while RO is closing?
 

tbennekik

New member
Local time
Today, 02:48
Joined
Jan 21, 2021
Messages
4
when you close rpt "RO" , you are telling it to close "RO" again while RO is closing?
"ROpzoeken Paswoorden" = the name of the report I want to close.
I already tried to close the report without the name, but I do get the same error.
In an other database I use the same DoCmd.Close statement for closing a report and there it is working fine.
On the web I read the error can occur with a corrupted database. But I already did the repair action without any result.
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:48
Joined
Sep 21, 2011
Messages
14,465
If you are in the Report_Close event, then the report is already closing? :unsure:
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:48
Joined
Oct 29, 2018
Messages
21,547
What we cannot see is from where are you trying to close the report? In other words, where is the code you posted above located? Is it on the same report you're trying to close?
 

isladogs

MVP / VIP
Local time
Today, 01:48
Joined
Jan 14, 2017
Messages
18,258
As others have stated, you can certainly use the line DoCmd.Close acReport, "ROpzoeken Paswoorden" but not in the Close event of that specific report. You just need:
Code:
Private Sub Report_Close()
DoCmd.OpenForm "Menu", acNormal
End Sub
 

tbennekik

New member
Local time
Today, 02:48
Joined
Jan 21, 2021
Messages
4
If you are in the Report_Close event, then the report is already closing? :unsure:
You are right. I stupid that I didn't see. I removed the "close" action and everything is working fine.
Thanks
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 01:48
Joined
Sep 12, 2006
Messages
15,713
Just a note

Error 2501 is a generic "action failed".

It's most often seen when a form fails to open for some reason. If it's something expected it's generally safe to ignore the error within an error handler.

Code:
...
...
on error goto fail
docmd.openform "someform"
exit sub

fail:
if err<>2501 then
  'you don't need to report error 2501 if the failure is not unexpected - if it's a different error, display the error.
   msgbox "Error " & err & "   Desc: " & err.description
end if
'resume statement not required as we are ending the sub anyway.
exit sub
 

Users who are viewing this thread

Top Bottom