DoCmd.Close - more complete code?

  • Thread starter Thread starter StargateFanNotAtHome
  • Start date Start date
S

StargateFanNotAtHome

I found DoCmd.Close works as promised via some posts I googled to, but
it did say we should be specific.

I found this code for that:

DoCmd.Close acReport, "Report_Index", acSaveNo

This is just one of the trials I did. The above is wrong because it
doesn't close and, actually nothing seems to happen. I don't even get
an error code. But DoCmd.Close works just fine.

However, there were warnings about this failing sometimes and I agree
with the posts that I read that I'd rather specify which item to
close, no matter that it is pretty straightforward.

I labelled the report "Index" whereas in the vbe, it shows as
"Report_Index". But neither work. What am I doing wrong, pls?

Well, that's it. Three things out of all the many things I googled
for that I couldn't figure out on my own (hence my 3 posts today).

Thanks everyone! :oD
 
Where are you using this code?

I have a function that I call from a popup menu, and in that I use:

Docmd.close acReport, Screen.ActiveReport.Name
 
DoCmd.Close acReport, "Report_Index", acSaveNo

DoCmd.Close acReport, Me.Name
Docmd.close acReport, Screen.ActiveReport.Name


Hi!

Well, the above do work, it's just that neither name the report
either, which leaves me back with code no different than the
DoCmd.Close.

....

Okay, I went and looked again. I had the name wrong, somehow. What
shows up in the vbe is, obviously now, not the report's name (d'uh!).
I
This page, here: http://msdn.microsoft.com/en-us/library/bb226008.aspx,
confirmed that I was on the right track.
As can be seen in the "Visual Basic for Applications" box, the
commands is, indeed, as I had found elsewhere on google:
DoCmd.Close acForm, "Order Review", acSaveYes

So I knew that my report name was probably what was at fault. Seems
to be working now, and I used this:

DoCmd.Close acReport, "Index Report", acSaveYes

I agree with the couple of posters whose advice I took, best to put
the actual report and form names in code of this type. I tend to
agree.

Thanks! :oD
 
message
DoCmd.Close acReport, Me.Name
Docmd.close acReport, Screen.ActiveReport.Name


Hi!

Well, the above do work, it's just that neither name the report
either, which leaves me back with code no different than the
DoCmd.Close.

Actually they are quite different.

DoCmd.Close acReport, Me.Name

will always close only the report from which it's running. The others will
close the currently active form, regardless of whether that form is running
the code or not. The situation could arise that a form with a Timer event
could pop into focus, 2 reports could be opening at the same time from
different processes.
 
Hi,
Well I will give you another point of view DON'T USE THE REPORT NAME
and you made my case for me.

DoCmd.Close acReport, "Report_Index", acSaveNo - DIDN'T Work

DoCmd.Close acReport, Me.Name DID Work - (you can add ,acSaveNo OR Yes to
this)
And btw Me.Name IS the name of the report - that is why it did work.

DoCmd.Close acReport, "Index Report", acSaveYes - DID work also BECAUSE you
had the correct name.

So why use the actual report name when you can type it wrong - use the
Me.Name - or if you know that the report is the active one the
screen.ActiveReport.Name.

And then what happens when you realize that for names of objects you
shouldn't use spaces and you change it to rptIndexReport. You have to
remember to go back into the code and change your code to close the report.
 
Back
Top