Open report AND close form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have been asked to learn access by my boss as the person who did it has
left and I have been thrown in at the deep end with everyone asking me to
change things. I have managed to get the basics but have found that some
things are not possible to do without an in-depth knowledge….. I have looked
at the many answers on this site and can’t find the answer to this little
problem so any help would be greatly appreciated.

We have a button on a form called frm_input and button1 which is pressed to
open a report called rpt_WeeklyCashIn and this works fine. But the form is
still open and if it is possible I would like to know how I can get it to
close the frm_input when rpt_WeeklyCashIn report opens. It may not be
possible, although I think it should be and it would be nice.

I would really appreciate it if any answers could be step-by-step and in
simple terms.
 
Open to form and go to design view then right click the button and select
Properties. Select Event and then “on-click†which will say “event
procedureâ€. Right click and select build. Select all the text between the
lines (between Private Sub button1_Click() and End Sub) and delete it.



Private Sub button1_Click()
On Error GoTo PreviewReport1_Click_Err

DoCmd.OpenReport "rpt_WeeklyCashIn", acViewPreview, "", "", acNormal
DoCmd.Close acForm, "frm_input"


PreviewReport1_Click_Exit:
Exit Sub

PreviewReport1_Click_Err:
MsgBox Error$
Resume PreviewReport1_Click_Exit

End Sub



Paste the code above into the space and save.

Hope this helps
 
What does all this mean (soory to bother you)

DoCmd.OpenReport "rpt_WeeklyCashIn", acViewPreview, "", "", acNormal
 
Basically when you use a computer (unless you’re on Star Trek) you need to
tell it what you want it to do (on Star Trek it will tell you ?). To do this
you use various bits of code (which can be placed either behind the form or
saved as a module which means you can use it for other forms on your D Base)
and when you action this code (by pressing a button, opening a form, clicking
the mouse or one of many other actions) the computer will perform the process
that you have “coded†it to do when this action is undertaken.

In this case

DoCmd **** tells the programme what you want it to do (OpenReport / OpenForm
/ etc)

Rpt_WeeklyCaskIn is the name of the report/form/query/etc you want to open.

acViewPreview is view that you want (you could have acDesign/acPreview/etc)

The1st Ҡis the space where you would put a filter name

The 2nd Ҡis the space you would use for a “WhereConditionâ€

acNormal is the window mode that you want

I have looked at your original question again and it may be a good idea to
ask your boss to pay for some training for you before asking you to start
re-coding the company’s systems – this may be a BIG mistake.
 
Macros are a little bit easier for a beginner to use. You can do the same in
a Macro that is started by a button on the form:
Create the Macro.
the first line Action would be OpenReport. At the bottom of the macro form
enter the name of the report in the Object name slot and the View (Print or
Preview.) Both have drop down menus so you don't have to type in the whole
thing.
In the next Action of the macro, do the same for Close. You will need to
Enter Form in the Object type slot and the name of the form in the Object
name slot but again, both are drop down menus.
Save and name the menu.
On your form go to the Properties of button1 and in the On click property,
use the drop down menu to select the macro you just created.
This does the same thing as the code that Wayne gave you.
 
Thank you both for your kind help. The code works perfectly and I have had a
some praise from a few people on “how quickly I’m learning the system†???

Oh and thanks as well for the tips about Macro's - I have just started to
look at these and they seem quite simply so I think I'll work with them for a
while.
 
The command proposed works fine but if I need to print directly it doesn’t
work.
I’m using
DoCmd.OpenReport "rpt_WeeklyCashIn", acViewNormal

And after this no more commands are execute include the docmd.close acform
Any more ideas?
Thanks,
Tyan


"Wayne-in-Manchester" escreveu:
 
Tyan said:
The command proposed works fine but if I need to print directly it
doesn't work.
I'm using
DoCmd.OpenReport "rpt_WeeklyCashIn", acViewNormal

And after this no more commands are execute include the docmd.close
acform Any more ideas?

Run the line of code that closes the form first. All additional lines in the
routine are still executed after that line.
 
I cannot do that because I need the values in the form to run the report.


"Rick Brandt" escreveu:
 
Tyan said:
I cannot do that because I need the values in the form to run the
report.

Why do you want the form to close when the report opens if the report needs
values found on the form? Replace the line that closes the form with...

Me.Visible = false

....then add a line of code in the Close event of the report that closes the
form. That way you aren't closiong it until it is no longer needed.
 
I rely don’t appreciate this king of solution because it forces me to change
the code of all reports, but it works.

Thanks,
Tyan


"Rick Brandt" escreveu:
 
Back
Top