Closing a form using vba

Rockape

Registered User.
Local time
Today, 15:11
Joined
Aug 24, 2007
Messages
271
hi all,

I have prepared a form with a preview button using the inbuilt wizard which will open a report. However when i press it the report stays under the form. Is there any way of amending the preview button code so that it will close the form or place it behind the report that is on screen (without having to create a macro!)

I'm sure this is some simple code which does the trick.

Note my form is popup and autocentred

regards to all
 
Is there any way of amending the preview button code so that it will close the form or place it behind the report that is on screen
Maybe either...

docmd.minimize OR

docmd.close

...before the "open report" code is executed.
 
If you make the Form a Pop-Up it will come to the front.
 
Maybe either...

docmd.minimize OR

docmd.close

...before the "open report" code is executed.


Thanks for promptness, tried it but failed (grateful for your comments):-

Private Sub Command10_Click()
On Error GoTo Err_Command10_Click

Dim stDocName As String

stDocName = "rep_Cheques collected"

DoCmd.Close frm_reports
DoCmd.OpenReport stDocName, acPreview


Exit_Command10_Click:
Exit Sub

Err_Command10_Click:
MsgBox Err.Description
Resume Exit_Command10_Click

End Sub
 
there is a close X button on it

Hi,

lol, quite.

I was just thinking that perhaps I could send it to the back. The problem I have is that this particular form has query parameters attached to it, i.e it queries a table for a particular date range. The moment I close the form the parameters are lost and the report wont load.

Regards
 
open the form in hidden view

Dim stDocName As String

stDocName = "your form name"
DoCmd.OpenForm stDocName, acHidden
 
open the form in hidden view

Dim stDocName As String

stDocName = "your form name"
DoCmd.OpenForm stDocName, acHidden

Thanks

acHidden worked a treat. Couldn't find it in Access97??? but it worked when i wrote it.

regards:)
 
glad i could help :-)

Hi,

sorry to bother you, but something is going wrong when i thought i had just cracked it.

I'll start from the beginnning.

I have a form which when i click on a button goes on to another form. Both are popups, so in effect the second form superimposes on top of the first.

In this second form I have two inputs which determine a range, which works fine with the query.

Whwn I create a report based on this query/form, the report logically falls behind both forms, hence my decision to hide both forms prior to opening the report.


Dim stDocName As String
Dim stDocNam As String
Dim stDocNa As String

stDocName = "rep_Cheques collected"
stDocNam = "frm_reports"
stDocNa = "Main Menu"


DoCmd.Close acForm, stDocNa
'DoCmd.OpenForm stDocNa, acHidden
DoCmd.OpenForm stDocNam, acHidden
DoCmd.OpenReport stDocName, acPreview


It seems it wont work when the bold line is active, hence why i close the form i the previous line.

With the following sequence, i.e.

DoCmd.Close acForm, stDocNa
DoCmd.OpenForm stDocNam, acHidden
DoCmd.OpenReport stDocName, acPreview

the program fails to deliver the preview of the report correctly.....(in fact report displays no results!!!

Help required!!!!!
 
Me.MyForm.Visible=False

Hi,
Grateful for assistance..


I'll start from the beginnning.

I have a form which when i click on a button goes on to another form. Both are popups, so in effect the second form superimposes on top of the first.

In this second form I have two inputs which determine a range, which works fine with the query.

Whwn I create a report based on this query/form, the report logically falls behind both forms, hence my decision to hide both forms prior to opening the report.


Dim stDocName As String
Dim stDocNam As String
Dim stDocNa As String

stDocName = "rep_Cheques collected"
stDocNam = "frm_reports"
stDocNa = "Main Menu"


DoCmd.Close acForm, stDocNa
'DoCmd.OpenForm stDocNa, acHidden
DoCmd.OpenForm stDocNam, acHidden
DoCmd.OpenReport stDocName, acPreview


It seems it wont work when the bold line is active, hence why i close the form in the previous line.

With the following sequence, i.e.

DoCmd.Close acForm, stDocNa
DoCmd.OpenForm stDocNam, acHidden
DoCmd.OpenReport stDocName, acPreview

the program fails to deliver the preview of the report correctly.....(in fact report displays no results!!!

Help required!!!!!
 
Last edited:
you are closing the form with the data on and then re opening it as hidden correct?

do you have to enter the data in the form you wish to display in the report?
if so the form wont re-open with the data you want to display!

if so your code would have to be what rockape first said!
Me.stDocNa.Visible = False
'or Me.[main menu].Visible = False
'or just Me.Visible = False
DoCmd.OpenForm stDocNam, acHidden
DoCmd.OpenReport stDocName, acPreview

try this
if i have understood you wrong, sorry
 
Hi,

this is what I have so far:-

DoCmd.Close acForm, stDocNa
(works)

Me.stDocNam.Visible = False
(Fails)

DoCmd.OpenReport stDocName, acPreview
DoCmd.Maximize
(These two lines work fine so long as the second line is disabled)


Regards







you are closing the form with the data on and then re opening it as hidden correct?

do you have to enter the data in the form you wish to display in the report?
if so the form wont re-open with the data you want to display!

if so your code would have to be what rockape first said!
Me.stDocNa.Visible = False
'or Me.[main menu].Visible = False
'or just Me.Visible = False
DoCmd.OpenForm stDocNam, acHidden
DoCmd.OpenReport stDocName, acPreview

try this
if i have understood you wrong, sorry
 
right sorry about how long it is taking to sort such a seemingly simple problem!

lets try a different aproach
forget about hiding the form just make the report pop-up infront of it!

on the report properties set popup to yes ,modal to no , auto resize to yes and auto center to yes
if you would like the report to cover the whole screen and to cover the database window
then in the report on open code type
DoCmd.Maximize

i think this should solve your problem and the report wil be visable over the forms

then if you would like to close the forms after the report is closed just use
docmd.close acform "yourformname"
on the close function of the report

im praying this works
sorry about the spelling
thanks
 
Last edited:
What's the point of opening a parameter form and hiding it right away before you've even had chance to check it?
 
Hi,
Therse nothing to check...

The button I press for the report to appear is located on the parameter form. Once I press this button I expect the form to hide so that what appears on screen is the maximised report. i.e. the parameters is basically a date range, so what appears on the report is a result of the list of items that comply with this date range.

Simple :)


What's the point of opening a parameter form and hiding it right away before you've even had chance to check it?
 

Users who are viewing this thread

Back
Top Bottom