Why does the following code not work? 
Author Message
 Why does the following code not work?

I am curios as to why the following code does not work?

Assume intListType = 12
...
    Assistant.Visible = False
    If intListType <> 99 Then
        DoCmd.Close acForm, "Reports", acSaveNo
        Create_OpenReport 'Creates and Saves a Report
        DoCmd.OpenReport "Report1", acViewPreview
        While Reports("Report1")
            DoCmd.DeleteObject acReport, "Report1"
        Wend
    End If
Exit Sub

TIA,
    Jeff R



Sat, 26 Feb 2005 00:53:30 GMT  
 Why does the following code not work?
I have to guess what you intended.

Next time, include your goal, and state the way "it doesn't work". Sometimes
you get compile errors. Spell them! Sometimes you get runtime errors.
Mention at least the number, and the violating line! Sometimes the result is
not quite what you expected. Formulate the (unwanted) result, and, most of
all, what should it be?

This having said: I am reading a code fragment with just one plain mistake:

while reports("report1")

"While" expects an expression that evaluates as either True or False. You
have used an expression that yields a report - if it is open. If it is NOT
open, this will "throw an error". Runtime.

Inside the while...wend, I see that you try to delete a report. But if you
delete a report, it is *gone*! Why? Is it only temporary?
A repeating loop as the while...wend is, is not necessary to delete *one*
object.

Should you want to wait until your report closes, then this is not the place
to check.
--
Regards,
Bas Cost Budde, Holland
website at http://www.heuveltop.nl/BasCB/msac_index.html

Quote:

>I am curios as to why the following code does not work?

>Assume intListType = 12
>...
>    Assistant.Visible = False
>    If intListType <> 99 Then
>        DoCmd.Close acForm, "Reports", acSaveNo
>        Create_OpenReport 'Creates and Saves a Report
>        DoCmd.OpenReport "Report1", acViewPreview
>        While Reports("Report1")
>            DoCmd.DeleteObject acReport, "Report1"
>        Wend
>    End If
>Exit Sub

>TIA,
>    Jeff R



Sat, 26 Feb 2005 01:59:43 GMT  
 Why does the following code not work?

Quote:

>I am curios as to why the following code does not work?

Well... quite a few problems here.

Quote:
>Assume intListType = 12
>...
>    Assistant.Visible = False
>    If intListType <> 99 Then
>        DoCmd.Close acForm, "Reports", acSaveNo
>        Create_OpenReport 'Creates and Saves a Report

Do you have a Sub in your project named Create_OpenReport? Does it
take any arguments?

Quote:
>        DoCmd.OpenReport "Report1", acViewPreview
>        While Reports("Report1")
>            DoCmd.DeleteObject acReport, "Report1"
>        Wend

A While/Wend loop will run forever until the While argument evaluates
to False. If all you want to do is delete the report just use the
DeleteObject line, and lose the loop.

I don't believe that code execution will stop at the OpenReport - this
will open the report and then instantly delete it, and I have NO idea
why you would want to do this!

Quote:
>    End If
>Exit Sub

>TIA,
>    Jeff R

                  John W. Vinson[MVP]    
    Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public


Sat, 26 Feb 2005 04:18:06 GMT  
 Why does the following code not work?
Here's the situation as in the code below...

Generate Report1
..Save Report1
Open Report1 in PrintPreview
..Close Report1..
Delete Report1

After the user has seen the report and printed it out and
closed the Print Preview. I would like to delete the
report. (Code not implemented yet to ask to save report
and ask for name, I can do this part.)

The code below is located in a module (outside of the
report).

My thought with the code was that while the report is open
keep looping in a while statement. When report closes then
delete the report.

Thank for your assistance,
Jeff

Quote:
>-----Original Message-----
>I have to guess what you intended.

>Next time, include your goal, and state the way "it

doesn't work". Sometimes
Quote:
>you get compile errors. Spell them! Sometimes you get
runtime errors.
>Mention at least the number, and the violating line!

Sometimes the result is
Quote:
>not quite what you expected. Formulate the (unwanted)

result, and, most of
Quote:
>all, what should it be?

>This having said: I am reading a code fragment with just
one plain mistake:

>while reports("report1")

>"While" expects an expression that evaluates as either
True or False. You
>have used an expression that yields a report - if it is
open. If it is NOT
>open, this will "throw an error". Runtime.

>Inside the while...wend, I see that you try to delete a
report. But if you
>delete a report, it is *gone*! Why? Is it only temporary?
>A repeating loop as the while...wend is, is not necessary
to delete *one*
>object.

>Should you want to wait until your report closes, then

this is not the place

- Show quoted text -

Quote:
>to check.
>--
>Regards,
>Bas Cost Budde, Holland
>website at http://www.heuveltop.nl/BasCB/msac_index.html


>>I am curios as to why the following code does not work?

>>Assume intListType = 12
>>...
>>    Assistant.Visible = False
>>    If intListType <> 99 Then
>>        DoCmd.Close acForm, "Reports", acSaveNo
>>        Create_OpenReport 'Creates and Saves a Report
>>        DoCmd.OpenReport "Report1", acViewPreview
>>        While Reports("Report1")
>>            DoCmd.DeleteObject acReport, "Report1"
>>        Wend
>>    End If
>>Exit Sub

>>TIA,
>>    Jeff R

>.



Sat, 26 Feb 2005 04:30:41 GMT  
 Why does the following code not work?
In Access 2000 or later you could do something like this:

    While CurrentProject.AllReports("Report1").IsLoaded
        DoEvents
    Wend
    DoCmd.DeleteObject acReport, "Report1"

If you're using Access 97 there's a function widely available that can
test whether the report is open.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Quote:
> Here's the situation as in the code below...

> Generate Report1
> ..Save Report1
> Open Report1 in PrintPreview
> ..Close Report1..
> Delete Report1

> After the user has seen the report and printed it out and
> closed the Print Preview. I would like to delete the
> report. (Code not implemented yet to ask to save report
> and ask for name, I can do this part.)

> The code below is located in a module (outside of the
> report).

> My thought with the code was that while the report is open
> keep looping in a while statement. When report closes then
> delete the report.

> Thank for your assistance,
> Jeff

> >-----Original Message-----
> >I have to guess what you intended.

> >Next time, include your goal, and state the way "it
> doesn't work". Sometimes
> >you get compile errors. Spell them! Sometimes you get
> runtime errors.
> >Mention at least the number, and the violating line!
> Sometimes the result is
> >not quite what you expected. Formulate the (unwanted)
> result, and, most of
> >all, what should it be?

> >This having said: I am reading a code fragment with just
> one plain mistake:

> >while reports("report1")

> >"While" expects an expression that evaluates as either
> True or False. You
> >have used an expression that yields a report - if it is
> open. If it is NOT
> >open, this will "throw an error". Runtime.

> >Inside the while...wend, I see that you try to delete a
> report. But if you
> >delete a report, it is *gone*! Why? Is it only temporary?
> >A repeating loop as the while...wend is, is not necessary
> to delete *one*
> >object.

> >Should you want to wait until your report closes, then
> this is not the place
> >to check.
> >--
> >Regards,
> >Bas Cost Budde, Holland
> >website at http://www.heuveltop.nl/BasCB/msac_index.html


> >>I am curios as to why the following code does not work?

> >>Assume intListType = 12
> >>...
> >>    Assistant.Visible = False
> >>    If intListType <> 99 Then
> >>        DoCmd.Close acForm, "Reports", acSaveNo
> >>        Create_OpenReport 'Creates and Saves a Report
> >>        DoCmd.OpenReport "Report1", acViewPreview
> >>        While Reports("Report1")
> >>            DoCmd.DeleteObject acReport, "Report1"
> >>        Wend
> >>    End If
> >>Exit Sub

> >>TIA,
> >>    Jeff R

> >.



Sat, 26 Feb 2005 08:18:08 GMT  
 Why does the following code not work?
A97:
   Do While SysCmd(acSysCmdGetObjectState, "yourReport") = acObjStateOpen

 will do, I guess.

--
Regards,
Bas Cost Budde, Holland
website at http://www.heuveltop.nl/BasCB/msac_index.html

Quote:

>If you're using Access 97 there's a function widely available that can
>test whether the report is open.



Sat, 26 Feb 2005 15:41:34 GMT  
 Why does the following code not work?
That would be the meat of it, yes.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)



Quote:
> A97:
>    Do While SysCmd(acSysCmdGetObjectState, "yourReport") =
acObjStateOpen

>  will do, I guess.

> --
> Regards,
> Bas Cost Budde, Holland
> website at http://www.heuveltop.nl/BasCB/msac_index.html


> >If you're using Access 97 there's a function widely available that
can
> >test whether the report is open.



Sat, 26 Feb 2005 22:29:33 GMT  
 Why does the following code not work?
In response to your questions...

Do you have a Sub in your project named Create_OpenReport?
..Yes (This part works ok.)
Does it take any arguments?
..No
A While/Wend loop will run forever until the While
argument evaluates to False. If all you want to do is
delete the report just use the DeleteObject line, and lose
the loop. I don't believe that code execution will stop at
the OpenReport - this will open the report and then
instantly delete it, and I have NO idea why you would want
to do this!
..While the report is Open do not perform the delete, when
user closes report from preview mode, then delete report.

Hope this clarifies some things for you..

Jeff R.

Quote:
>-----Original Message-----
>On Mon, 9 Sep 2002 09:53:30 -0700, "Jeff R"

>>I am curios as to why the following code does not work?

>Well... quite a few problems here.

>>Assume intListType = 12
>>...
>>    Assistant.Visible = False
>>    If intListType <> 99 Then
>>        DoCmd.Close acForm, "Reports", acSaveNo
>>        Create_OpenReport 'Creates and Saves a Report

>Do you have a Sub in your project named

Create_OpenReport? Does it

- Show quoted text -

Quote:
>take any arguments?

>>        DoCmd.OpenReport "Report1", acViewPreview
>>        While Reports("Report1")
>>            DoCmd.DeleteObject acReport, "Report1"
>>        Wend

>A While/Wend loop will run forever until the While
argument evaluates
>to False. If all you want to do is delete the report just
use the
>DeleteObject line, and lose the loop.

>I don't believe that code execution will stop at the
OpenReport - this
>will open the report and then instantly delete it, and I
have NO idea
>why you would want to do this!

>>    End If
>>Exit Sub

>>TIA,
>>    Jeff R

>                  John W. Vinson[MVP]    
>    Come for live chats every Tuesday and Thursday
>http://go.compuserve.com/msdevapps?loc=us&access=public
>.



Mon, 28 Feb 2005 00:56:33 GMT  
 Why does the following code not work?


Quote:
>..While the report is Open do not perform the delete, when
>user closes report from preview mode, then delete report.

See Jeff, Dirk and Bas's answers eslewhere in the thread.

                  John W. Vinson[MVP]    
    Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public



Mon, 28 Feb 2005 01:42:17 GMT  
 Why does the following code not work?
Tried...

Do While SysCmd(acSysCmdGetObjectState, acReport,
    "Report1") = acObjStateOpen
Loop
DoCmd.DeleteObject acReport, "Report1"

...but this cause the system to freeze while this loop is
being performed. The report does not finish coming up  in
PrintPreview.

Jeff R

Quote:
>-----Original Message-----
>That would be the meat of it, yes.

>--
>Dirk Goldgar, MS Access MVP
>www.datagnostics.com

>(please reply to the newsgroup)



>> A97:
>>    Do While SysCmd

(acSysCmdGetObjectState, "yourReport") =
Quote:
>acObjStateOpen

>>  will do, I guess.

>> --
>> Regards,
>> Bas Cost Budde, Holland
>> website at http://www.heuveltop.nl/BasCB/msac_index.html




Quote:

>> >If you're using Access 97 there's a function widely
available that
>can
>> >test whether the report is open.

>.



Mon, 28 Feb 2005 01:44:42 GMT  
 Why does the following code not work?
You left out the DoEvents statement that must go inside the loop.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Quote:
> Tried...

> Do While SysCmd(acSysCmdGetObjectState, acReport,
>     "Report1") = acObjStateOpen
> Loop
> DoCmd.DeleteObject acReport, "Report1"

> ...but this cause the system to freeze while this loop is
> being performed. The report does not finish coming up  in
> PrintPreview.

> Jeff R
> >-----Original Message-----
> >That would be the meat of it, yes.

> >--
> >Dirk Goldgar, MS Access MVP
> >www.datagnostics.com

> >(please reply to the newsgroup)



> >> A97:
> >>    Do While SysCmd
> (acSysCmdGetObjectState, "yourReport") =
> >acObjStateOpen

> >>  will do, I guess.

> >> --
> >> Regards,
> >> Bas Cost Budde, Holland
> >> website at http://www.heuveltop.nl/BasCB/msac_index.html



> >> >If you're using Access 97 there's a function widely
> available that
> >can
> >> >test whether the report is open.

> >.



Mon, 28 Feb 2005 01:59:05 GMT  
 Why does the following code not work?
That works.

Thanks guys for all your help on this issue.

Jeff

Quote:
>-----Original Message-----
>You left out the DoEvents statement that must go inside
the loop.

>--
>Dirk Goldgar, MS Access MVP
>www.datagnostics.com

>(please reply to the newsgroup)



>> Tried...

>> Do While SysCmd(acSysCmdGetObjectState, acReport,
>>     "Report1") = acObjStateOpen
>> Loop
>> DoCmd.DeleteObject acReport, "Report1"

>> ...but this cause the system to freeze while this loop
is
>> being performed. The report does not finish coming up  
in
>> PrintPreview.

>> Jeff R
>> >-----Original Message-----
>> >That would be the meat of it, yes.

>> >--
>> >Dirk Goldgar, MS Access MVP
>> >www.datagnostics.com

>> >(please reply to the newsgroup)



>> >> A97:
>> >>    Do While SysCmd
>> (acSysCmdGetObjectState, "yourReport") =
>> >acObjStateOpen

>> >>  will do, I guess.

>> >> --
>> >> Regards,
>> >> Bas Cost Budde, Holland
>> >> website at

http://www.heuveltop.nl/BasCB/msac_index.html

- Show quoted text -

Quote:



>> >> >If you're using Access 97 there's a function widely
>> available that
>> >can
>> >> >test whether the report is open.

>> >.

>.



Mon, 28 Feb 2005 02:05:28 GMT  
 Why does the following code not work?
Extremely Windows! These Processes Are Not Nice! (I'm sorry)

--
Regards,
Bas Cost Budde, Holland
website at http://www.heuveltop.nl/BasCB/msac_index.html
Please post replies to the newsgroup so everyone can benefit

Quote:

>You left out the DoEvents statement that must go inside the loop.



Mon, 28 Feb 2005 02:40:38 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. this code does not work, why?

2. Help Please...Code does not work why?

3. Why code will not work?

4. Why does this piece of code work with Word 97 but not Word 2000

5. why will this code not work

6. Find/Replace code not working - why?

7. Why this code does not work:

8. why the @#$@% does this code not work

9. Anyone know why this code only works in 32bit and not 16 bit vb 4

10. Why this code does not work properly?

11. Why does this code not work?

12. Why does this simple code not work?

 

 
Powered by phpBB® Forum Software