UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Command to run referenced query for report, then close form    
 
   
djleister
post Sep 19 2008, 11:36 PM
Post #1

UtterAccess Veteran
Posts: 407



I have a form where the user selects a project from a combo box, once selected the detail is displayed within the form. I have a button which allows for the user to print preview the selected report howver when selected the report open behind the form so I used this command:
ECHO False
DoCmd.Close
DoCmd.Maximize
DoCmd.OpenReport "rptEmployees", acViewPreview
ECHO True

The problem is that the form closes but the reference to the combo box of which project to display did not have time to query and run, so I get the message box to type in the project number. How do I have the report run, display for the referenced project and the form to close all in one command?

Thank you,
Deborah
Go to the top of the page
 
+
HiTechCoach
post Sep 20 2008, 12:03 AM
Post #2

UtterAccess VIP
Posts: 18,396
From: Oklahoma City, Oklahoma



In the form try using this:

CODE
Me.Visible = False    ' hide form before reporting the report

DoCmd.OpenReport "rptEmployees", acViewPreview


In the form's On Open event, I you could use something like:

CODE
If CurrentProject.AllForms("frmPopReportParms").IsLoaded = False Then

  MsgBox "Can't run this report."

  Cancel = true

End if


Edited by: HiTechCoach on Sat Sep 20 1:08:06 EDT 2008.
Go to the top of the page
 
+
djleister
post Sep 20 2008, 12:19 AM
Post #3

UtterAccess Veteran
Posts: 407



I have a command button which allows the user to print preview the report for the slected project, do I code on the onclick of the button?
Go to the top of the page
 
+
HiTechCoach
post Sep 20 2008, 12:49 AM
Post #4

UtterAccess VIP
Posts: 18,396
From: Oklahoma City, Oklahoma



Yes. I assumed that this was the code for the click event.

TIP: when posting VBA code, include all the code for the event

Example
CODE
Private Sub cmdPreviewReport_Click()

  Me.Visible = false

  DoCmd.OpenReport "rptEmployees", acViewPreview



End Sub
Go to the top of the page
 
+
polant
post Sep 20 2008, 04:18 AM
Post #5

UtterAccess Guru
Posts: 583
From: Cyprus



Deborah

Not sure if I fully understand the problem, however I will make some comments that may help.

- If the report opens behind the form, then probably this is because the PopUp and/or Modal properties of the form are set to Yes.

- When I want to close a form but hold on to the value of a control for a little longer, then I assign the value of control to a variable before the docmd.close statement. The variable exists until the sub finishes. So it goes about like this:

variable = me!control

docmd.close

use variable to do whatever is to be done

end sub
Go to the top of the page
 
+
djleister
post Sep 21 2008, 11:40 PM
Post #6

UtterAccess Veteran
Posts: 407



Again, thank you! It works great.

Deborah
Go to the top of the page
 
+
djleister
post Sep 21 2008, 11:42 PM
Post #7

UtterAccess Veteran
Posts: 407



Thanks Polant, This information helps me too.
Go to the top of the page
 
+
HiTechCoach
post Sep 22 2008, 10:33 AM
Post #8

UtterAccess VIP
Posts: 18,396
From: Oklahoma City, Oklahoma



You're welcome! (IMG:http://www.utteraccess.com/forum/style_emoticons/default/sad.gif)

Glad we could assist again.

(IMG:http://www.utteraccess.com/forum/style_emoticons/default/uarulez2.gif)
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 24th May 2013 - 01:23 PM