preview a report

N

Nick T

Hi,
Have a form on which i have a cmd button. I want to click the button to
preview a report. Iv used the 'wizard' and got the following code:

Private Sub Command27_Click()
On Error GoTo Err_Command27_Click

Dim stDocName As String

stDocName = "Invoice"
DoCmd.OpenReport stDocName, acPreview

Exit_Command27_Click:
Exit Sub

Err_Command27_Click:
MsgBox Err.Description
Resume Exit_Command27_Click

End Sub

When i click the button, it askes me to enter my 'Invoice No' into another
window which 'pops up', however, i want the 'Invoice No' to match a text box
which is on my form. Why is this other window poping up, and any suggestions
around this prob??

Many thanks
 
N

Nick T

PS.
Its the 'Parameter Value' i need to enter....
Can i write this into the code, eg. me.parameter value = me.textboxA

.......or code to that affect?

Many thanks
 
S

Steve

Hello Nick,

Change your DoCmd.OpenReport line to:
DoCmd.OpenReport stDocName, acPreview,,"[Invoice No] = '" &
Forms!NameOfYourForm!TextBoxA & "'"

Note - Before the & is a single quote followed by a double quote. At the end
is a single quote enclosed between two double quotes.

I have assumed your "Invoice No" is a string data type.

Steve
(e-mail address removed)
 
J

John Spencer

Also if you are going to use the method proposed by Steve then you need to
remove the parameter prompt from the report's record source.

Another way to handle this is to change the report's record source and replace
the parameter with a reference to the form's control.

In the query you would use
Forms![NameOfYourForm]![NameOfTheControlOnTheForm]
as the criteria.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Hello Nick,

Change your DoCmd.OpenReport line to:
DoCmd.OpenReport stDocName, acPreview,,"[Invoice No] = '" &
Forms!NameOfYourForm!TextBoxA & "'"

Note - Before the & is a single quote followed by a double quote. At the end
is a single quote enclosed between two double quotes.

I have assumed your "Invoice No" is a string data type.

Steve
(e-mail address removed)


Nick T said:
PS.
Its the 'Parameter Value' i need to enter....
Can i write this into the code, eg. me.parameter value = me.textboxA

......or code to that affect?

Many thanks
 
N

Nick T

Hi,
Thanks for the suggestions.....
How do i remove the parameter prompt??

Many thanks

John Spencer said:
Also if you are going to use the method proposed by Steve then you need to
remove the parameter prompt from the report's record source.

Another way to handle this is to change the report's record source and replace
the parameter with a reference to the form's control.

In the query you would use
Forms![NameOfYourForm]![NameOfTheControlOnTheForm]
as the criteria.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Hello Nick,

Change your DoCmd.OpenReport line to:
DoCmd.OpenReport stDocName, acPreview,,"[Invoice No] = '" &
Forms!NameOfYourForm!TextBoxA & "'"

Note - Before the & is a single quote followed by a double quote. At the end
is a single quote enclosed between two double quotes.

I have assumed your "Invoice No" is a string data type.

Steve
(e-mail address removed)


Nick T said:
PS.
Its the 'Parameter Value' i need to enter....
Can i write this into the code, eg. me.parameter value = me.textboxA

......or code to that affect?

Many thanks


:

Hi,
Have a form on which i have a cmd button. I want to click the button to
preview a report. Iv used the 'wizard' and got the following code:

Private Sub Command27_Click()
On Error GoTo Err_Command27_Click

Dim stDocName As String

stDocName = "Invoice"
DoCmd.OpenReport stDocName, acPreview

Exit_Command27_Click:
Exit Sub

Err_Command27_Click:
MsgBox Err.Description
Resume Exit_Command27_Click

End Sub

When i click the button, it askes me to enter my 'Invoice No' into
another
window which 'pops up', however, i want the 'Invoice No' to match a text
box
which is on my form. Why is this other window poping up, and any
suggestions
around this prob??

Many thanks
.
 
J

John Spencer

Open the report in design view
Open the report's source
Find and remove the prompt.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Nick said:
Hi,
Thanks for the suggestions.....
How do i remove the parameter prompt??

Many thanks

John Spencer said:
Also if you are going to use the method proposed by Steve then you need to
remove the parameter prompt from the report's record source.

Another way to handle this is to change the report's record source and replace
the parameter with a reference to the form's control.

In the query you would use
Forms![NameOfYourForm]![NameOfTheControlOnTheForm]
as the criteria.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Hello Nick,

Change your DoCmd.OpenReport line to:
DoCmd.OpenReport stDocName, acPreview,,"[Invoice No] = '" &
Forms!NameOfYourForm!TextBoxA & "'"

Note - Before the & is a single quote followed by a double quote. At the end
is a single quote enclosed between two double quotes.

I have assumed your "Invoice No" is a string data type.

Steve
(e-mail address removed)


PS.
Its the 'Parameter Value' i need to enter....
Can i write this into the code, eg. me.parameter value = me.textboxA

......or code to that affect?

Many thanks


:

Hi,
Have a form on which i have a cmd button. I want to click the button to
preview a report. Iv used the 'wizard' and got the following code:

Private Sub Command27_Click()
On Error GoTo Err_Command27_Click

Dim stDocName As String

stDocName = "Invoice"
DoCmd.OpenReport stDocName, acPreview

Exit_Command27_Click:
Exit Sub

Err_Command27_Click:
MsgBox Err.Description
Resume Exit_Command27_Click

End Sub

When i click the button, it askes me to enter my 'Invoice No' into
another
window which 'pops up', however, i want the 'Invoice No' to match a text
box
which is on my form. Why is this other window poping up, and any
suggestions
around this prob??

Many thanks
.
 

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

Similar Threads


Top