A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

DoCmd.Close - more complete code?



 
 
Thread Tools Display Modes
  #1  
Old August 7th, 2009, 08:01 PM posted to microsoft.public.access.gettingstarted
StargateFanNotAtHome[_2_]
external usenet poster
 
Posts: 11
Default DoCmd.Close - more complete code?

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! D
  #2  
Old August 7th, 2009, 08:13 PM posted to microsoft.public.access.gettingstarted
Arvin Meyer [MVP][_2_]
external usenet poster
 
Posts: 2,310
Default DoCmd.Close - more complete code?

Try using:

DoCmd.Close acReport, Me.Name
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"StargateFanNotAtHome" wrote in
message
...
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! D



  #3  
Old August 7th, 2009, 09:06 PM posted to microsoft.public.access.gettingstarted
Dale Fye
external usenet poster
 
Posts: 2,651
Default DoCmd.Close - more complete code?

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


----
HTH
Dale



"StargateFanNotAtHome" wrote:

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! D

  #4  
Old August 7th, 2009, 11:14 PM posted to microsoft.public.access.gettingstarted
StargateFanNotAtHome[_2_]
external usenet poster
 
Posts: 11
Default DoCmd.Close - more complete code?

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, he 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! D
  #5  
Old August 8th, 2009, 05:49 AM posted to microsoft.public.access.gettingstarted
Arvin Meyer [MVP][_2_]
external usenet poster
 
Posts: 2,310
Default DoCmd.Close - more complete code?


"StargateFanNotAtHome" wrote in
message
...
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.


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.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


  #6  
Old August 10th, 2009, 02:01 PM posted to microsoft.public.access.gettingstarted
CraigH
external usenet poster
 
Posts: 50
Default DoCmd.Close - more complete code?

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.



"StargateFanNotAtHome" wrote:

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, he 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! D

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:27 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.