Prompts in a report

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

Guest

I currently have a report that initially prompts for a Project Number when
open.

After the report is generated, I'd then like for a second prompt asking the
user if he'd like to print the current report for search for another project.
If he opts to search for another project, I'd like to see the prompt again
for the Project Number.

Am I able to do this in Access? If so, please advise.
 
Karen

Instead of using a parameter in the report's underlying query open it from a
dialogue form with a text box txtProjectNumber and a button with code along
the following lines in its Click event procedure:

Const conREPORTNAME = "YourReportName"
Const conMESSAGE = "Do you wish to print the report?"
Dim strCriteria As String

strCriteria = "[Project Number] = " & Me.txtProjectNumber

' hide form
Me.Visible = False

' open report in print preview
DoCmd.OpenReport conREPORTNAME, _
View:=acViewPreview, _
WhereCondition:=strCriteria

' if user confirms, print report
If MsgBox(conMESSAGE, vbQuestion + vbYesNo, "Print Report") = vbYes Then
' close print preview
DoCmd.Close acReport, conREPORTNAME
' print report
DoCmd.OpenReport conREPORTNAME, _
View:=acViewNormal, _
WhereCondition:=strCriteria
End If

' show form
Me.Visible = True
' clear text box ready for next search
Me.txtProjectNumber = ""
' move focus to report in preview if open
On Error Resume Next
DoCmd.SelectObject acReport, conREPORTNAME

Instead of opening the report directly open the form. The user then enters
the project number in the text box and clicks the button. I've assumed the
project number is a number data type; if its text data type change one line
to:

strCriteria = "[Project Number ] = """ & Me. txtProjectNumber & """"

Ken Sheridan
Stafford, England
 
Karen

Instead of using a parameter in the report's underlying query open it from a
dialogue form with a text box txtProjectNumber and a button with code along
the following lines in its Click event procedure:

Const conREPORTNAME = "YourReportName"
Const conMESSAGE = "Do you wish to print the report?"
Dim strCriteria As String

strCriteria = "[Project Number] = " & Me.txtProjectNumber

' hide form
Me.Visible = False

' open report in print preview
DoCmd.OpenReport conREPORTNAME, _
View:=acViewPreview, _
WhereCondition:=strCriteria

' if user confirms, print report
If MsgBox(conMESSAGE, vbQuestion + vbYesNo, "Print Report") = vbYes Then
' close print preview
DoCmd.Close acReport, conREPORTNAME
' print report
DoCmd.OpenReport conREPORTNAME, _
View:=acViewNormal, _
WhereCondition:=strCriteria
End If

' show form
Me.Visible = True
' clear text box ready for next search
Me.txtProjectNumber = ""
' move focus to report in preview if open
On Error Resume Next
DoCmd.SelectObject acReport, conREPORTNAME

Instead of opening the report directly open the form. The user then enters
the project number in the text box and clicks the button. I've assumed the
project number is a number data type; if its text data type change one line
to:

strCriteria = "[Project Number ] = """ & Me. txtProjectNumber & """"

Ken Sheridan
Stafford, England
 
First, thanks for all this detail! I had no idea it would be so troublesome.
I will try it and respond as to how it works thereafter.

Right now, I've had to close out the report and reopen it each time to do
subsequent searches in the report. Is that the only way?
--
Thanks, Karen


Ken Sheridan said:
Karen

Instead of using a parameter in the report's underlying query open it from a
dialogue form with a text box txtProjectNumber and a button with code along
the following lines in its Click event procedure:

Const conREPORTNAME = "YourReportName"
Const conMESSAGE = "Do you wish to print the report?"
Dim strCriteria As String

strCriteria = "[Project Number] = " & Me.txtProjectNumber

' hide form
Me.Visible = False

' open report in print preview
DoCmd.OpenReport conREPORTNAME, _
View:=acViewPreview, _
WhereCondition:=strCriteria

' if user confirms, print report
If MsgBox(conMESSAGE, vbQuestion + vbYesNo, "Print Report") = vbYes Then
' close print preview
DoCmd.Close acReport, conREPORTNAME
' print report
DoCmd.OpenReport conREPORTNAME, _
View:=acViewNormal, _
WhereCondition:=strCriteria
End If

' show form
Me.Visible = True
' clear text box ready for next search
Me.txtProjectNumber = ""
' move focus to report in preview if open
On Error Resume Next
DoCmd.SelectObject acReport, conREPORTNAME

Instead of opening the report directly open the form. The user then enters
the project number in the text box and clicks the button. I've assumed the
project number is a number data type; if its text data type change one line
to:

strCriteria = "[Project Number ] = """ & Me. txtProjectNumber & """"

Ken Sheridan
Stafford, England

Karen said:
I currently have a report that initially prompts for a Project Number when
open.

After the report is generated, I'd then like for a second prompt asking the
user if he'd like to print the current report for search for another project.
If he opts to search for another project, I'd like to see the prompt again
for the Project Number.

Am I able to do this in Access? If so, please advise.
 
Thanks Ken,

Everything works through the prompt to print. After it asks if I wish to
print and I select "No", I get a message from which I can select End or
Debug. Neither option brings me back to the form to enter another Project
Number.

The system highlights the last Me.txtProjectNumber = "" as though there's an
error in this language. Please advise. FYI - Project Number is a text field.

However, if I select "Yes", it prints.
--
Thanks, Karen


Ken Sheridan said:
Karen

Instead of using a parameter in the report's underlying query open it from a
dialogue form with a text box txtProjectNumber and a button with code along
the following lines in its Click event procedure:

Const conREPORTNAME = "YourReportName"
Const conMESSAGE = "Do you wish to print the report?"
Dim strCriteria As String

strCriteria = "[Project Number] = " & Me.txtProjectNumber

' hide form
Me.Visible = False

' open report in print preview
DoCmd.OpenReport conREPORTNAME, _
View:=acViewPreview, _
WhereCondition:=strCriteria

' if user confirms, print report
If MsgBox(conMESSAGE, vbQuestion + vbYesNo, "Print Report") = vbYes Then
' close print preview
DoCmd.Close acReport, conREPORTNAME
' print report
DoCmd.OpenReport conREPORTNAME, _
View:=acViewNormal, _
WhereCondition:=strCriteria
End If

' show form
Me.Visible = True
' clear text box ready for next search
Me.txtProjectNumber = ""
' move focus to report in preview if open
On Error Resume Next
DoCmd.SelectObject acReport, conREPORTNAME

Instead of opening the report directly open the form. The user then enters
the project number in the text box and clicks the button. I've assumed the
project number is a number data type; if its text data type change one line
to:

strCriteria = "[Project Number ] = """ & Me. txtProjectNumber & """"

Ken Sheridan
Stafford, England

Karen said:
I currently have a report that initially prompts for a Project Number when
open.

After the report is generated, I'd then like for a second prompt asking the
user if he'd like to print the current report for search for another project.
If he opts to search for another project, I'd like to see the prompt again
for the Project Number.

Am I able to do this in Access? If so, please advise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top