how do i get only one record to print

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

Guest

I have a Form and only want to print the Record that is displayed. On the
Form I have a command button that opens up a report that is supposed to show
the current record. However, currently it is previewing all the records in
the database - the code for this is shown below . (The ECMA is the unique
field)

Private Sub Command300_Click()
On Error GoTo Err_Command300_Click

Dim stDocName As String
Dim strWhere As String

strWhere = "[ECMA] = """ & Me.txtEMCA & """"

stDocName = "ProductDetails1"
DoCmd.OpenReport stDocName, acPreview, strWhere



Exit_Command300_Click:
Exit Sub

Err_Command300_Click:
MsgBox Err.Description
Resume Exit_Command300_Click

End Sub
 
Kirt,

I think you're missing a comma. You need to leave an empty spot for the
query filter parameter, if you're supplying a where clause.

DoCmd.OpenReport stDocName, acPreview,,strWhere

Jerry
 
Kirt84,

I would use the below line...

Private Sub Command300_Click()
DoCmd.OpenReport "ProductDetails1", acViewPreview, , "[ECMA]=' " &
Me![EMCA] & " ' "
End Sub

However, if you want to just fix the strWhere line then below should do it.
Also, you may need another comma after acPreview (so there would be 2
commas). I also noticed ECMA and then Me![txtEMCA], are they suppose to be
the same? If there are suppose to be different ignore that.

If a text field: strWhere = "[ECMA]=' " & Me![EMCA] & " ' "


If a numeric field: strWhere = "[ECMA]=" & Me![txtEMCA]

HTH,
Gina Whipp
 
Thank you - this is now only previewing the one Record, however no
information is populated in the text boxes on the Report.
ECMA is the name of the field on the table and txtECMA is the name of the
text box. The code I have put in is below:

Private Sub Command300_Click()
On Error GoTo Err_Command300_Click

Dim stDocName As String
Dim strWhere As String

strWhere = "[ECMA]=" & Me![EMCA]

stDocName = "ProductDetails1"
DoCmd.OpenReport "ProductDetails1", acViewPreview, , "[ECMA]=' " &
Me![txtEMCA] & " ' "



Exit_Command300_Click:
Exit Sub

Err_Command300_Click:
MsgBox Err.Description
Resume Exit_Command300_Click

End Sub


--
Thank you for your help


Gina Whipp said:
Kirt84,

I would use the below line...

Private Sub Command300_Click()
DoCmd.OpenReport "ProductDetails1", acViewPreview, , "[ECMA]=' " &
Me![EMCA] & " ' "
End Sub

However, if you want to just fix the strWhere line then below should do it.
Also, you may need another comma after acPreview (so there would be 2
commas). I also noticed ECMA and then Me![txtEMCA], are they suppose to be
the same? If there are suppose to be different ignore that.

If a text field: strWhere = "[ECMA]=' " & Me![EMCA] & " ' "


If a numeric field: strWhere = "[ECMA]=" & Me![txtEMCA]

HTH,
Gina Whipp


Kirt84 said:
I have a Form and only want to print the Record that is displayed. On the
Form I have a command button that opens up a report that is supposed to
show
the current record. However, currently it is previewing all the records in
the database - the code for this is shown below . (The ECMA is the unique
field)

Private Sub Command300_Click()
On Error GoTo Err_Command300_Click

Dim stDocName As String
Dim strWhere As String

strWhere = "[ECMA] = """ & Me.txtEMCA & """"

stDocName = "ProductDetails1"
DoCmd.OpenReport stDocName, acPreview, strWhere



Exit_Command300_Click:
Exit Sub

Err_Command300_Click:
MsgBox Err.Description
Resume Exit_Command300_Click

End Sub
 
What is the source of the report? A query??? Take a look at the query, can
you find the ECMA record in the query?

Kirt84 said:
Thank you - this is now only previewing the one Record, however no
information is populated in the text boxes on the Report.
ECMA is the name of the field on the table and txtECMA is the name of the
text box. The code I have put in is below:

Private Sub Command300_Click()
On Error GoTo Err_Command300_Click

Dim stDocName As String
Dim strWhere As String

strWhere = "[ECMA]=" & Me![EMCA]

stDocName = "ProductDetails1"
DoCmd.OpenReport "ProductDetails1", acViewPreview, , "[ECMA]=' " &
Me![txtEMCA] & " ' "



Exit_Command300_Click:
Exit Sub

Err_Command300_Click:
MsgBox Err.Description
Resume Exit_Command300_Click

End Sub


--
Thank you for your help


Gina Whipp said:
Kirt84,

I would use the below line...

Private Sub Command300_Click()
DoCmd.OpenReport "ProductDetails1", acViewPreview, , "[ECMA]=' " &
Me![EMCA] & " ' "
End Sub

However, if you want to just fix the strWhere line then below should do
it.
Also, you may need another comma after acPreview (so there would be 2
commas). I also noticed ECMA and then Me![txtEMCA], are they suppose to
be
the same? If there are suppose to be different ignore that.

If a text field: strWhere = "[ECMA]=' " & Me![EMCA] & " ' "


If a numeric field: strWhere = "[ECMA]=" & Me![txtEMCA]

HTH,
Gina Whipp


Kirt84 said:
I have a Form and only want to print the Record that is displayed. On
the
Form I have a command button that opens up a report that is supposed to
show
the current record. However, currently it is previewing all the records
in
the database - the code for this is shown below . (The ECMA is the
unique
field)

Private Sub Command300_Click()
On Error GoTo Err_Command300_Click

Dim stDocName As String
Dim strWhere As String

strWhere = "[ECMA] = """ & Me.txtEMCA & """"

stDocName = "ProductDetails1"
DoCmd.OpenReport stDocName, acPreview, strWhere



Exit_Command300_Click:
Exit Sub

Err_Command300_Click:
MsgBox Err.Description
Resume Exit_Command300_Click

End Sub
 
The source of the Report is the Form. I done a Save As on the Form and saved
it in Report format. The fields on the Report are sourced from the Form - not
sure why it doesn't work?
--
Thank you for your help


Gina Whipp said:
What is the source of the report? A query??? Take a look at the query, can
you find the ECMA record in the query?

Kirt84 said:
Thank you - this is now only previewing the one Record, however no
information is populated in the text boxes on the Report.
ECMA is the name of the field on the table and txtECMA is the name of the
text box. The code I have put in is below:

Private Sub Command300_Click()
On Error GoTo Err_Command300_Click

Dim stDocName As String
Dim strWhere As String

strWhere = "[ECMA]=" & Me![EMCA]

stDocName = "ProductDetails1"
DoCmd.OpenReport "ProductDetails1", acViewPreview, , "[ECMA]=' " &
Me![txtEMCA] & " ' "



Exit_Command300_Click:
Exit Sub

Err_Command300_Click:
MsgBox Err.Description
Resume Exit_Command300_Click

End Sub


--
Thank you for your help


Gina Whipp said:
Kirt84,

I would use the below line...

Private Sub Command300_Click()
DoCmd.OpenReport "ProductDetails1", acViewPreview, , "[ECMA]=' " &
Me![EMCA] & " ' "
End Sub

However, if you want to just fix the strWhere line then below should do
it.
Also, you may need another comma after acPreview (so there would be 2
commas). I also noticed ECMA and then Me![txtEMCA], are they suppose to
be
the same? If there are suppose to be different ignore that.

If a text field: strWhere = "[ECMA]=' " & Me![EMCA] & " ' "


If a numeric field: strWhere = "[ECMA]=" & Me![txtEMCA]

HTH,
Gina Whipp


I have a Form and only want to print the Record that is displayed. On
the
Form I have a command button that opens up a report that is supposed to
show
the current record. However, currently it is previewing all the records
in
the database - the code for this is shown below . (The ECMA is the
unique
field)

Private Sub Command300_Click()
On Error GoTo Err_Command300_Click

Dim stDocName As String
Dim strWhere As String

strWhere = "[ECMA] = """ & Me.txtEMCA & """"

stDocName = "ProductDetails1"
DoCmd.OpenReport stDocName, acPreview, strWhere



Exit_Command300_Click:
Exit Sub

Err_Command300_Click:
MsgBox Err.Description
Resume Exit_Command300_Click

End Sub
 
Okay, I have never done a report like that but I just did one to see what
happens. And I see it takes on the same Record Source as the form, so what
is the Record Source of the form? I also noticed that my calculated fields
(the ones located directly on the form show #Error). I also noticed that is
shows every record, so I fixed my button to just show me whatever record I
was previewing.

After doing all that, the source of your report is not the form but the
Record Source of the form, so once again, what is the Record Source of the
report? I know you can see the information on the form but something must
have changed which is why I want you to look at the Record Source of the
report.

I am not sure why it doesn't work either but might as well start with
obvious and move on from there.

Gina Whipp

Kirt84 said:
The source of the Report is the Form. I done a Save As on the Form and
saved
it in Report format. The fields on the Report are sourced from the Form -
not
sure why it doesn't work?
--
Thank you for your help


Gina Whipp said:
What is the source of the report? A query??? Take a look at the query,
can
you find the ECMA record in the query?

Kirt84 said:
Thank you - this is now only previewing the one Record, however no
information is populated in the text boxes on the Report.
ECMA is the name of the field on the table and txtECMA is the name of
the
text box. The code I have put in is below:

Private Sub Command300_Click()
On Error GoTo Err_Command300_Click

Dim stDocName As String
Dim strWhere As String

strWhere = "[ECMA]=" & Me![EMCA]

stDocName = "ProductDetails1"
DoCmd.OpenReport "ProductDetails1", acViewPreview, , "[ECMA]=' " &
Me![txtEMCA] & " ' "



Exit_Command300_Click:
Exit Sub

Err_Command300_Click:
MsgBox Err.Description
Resume Exit_Command300_Click

End Sub


--
Thank you for your help


:

Kirt84,

I would use the below line...

Private Sub Command300_Click()
DoCmd.OpenReport "ProductDetails1", acViewPreview, , "[ECMA]=' "
&
Me![EMCA] & " ' "
End Sub

However, if you want to just fix the strWhere line then below should
do
it.
Also, you may need another comma after acPreview (so there would be 2
commas). I also noticed ECMA and then Me![txtEMCA], are they suppose
to
be
the same? If there are suppose to be different ignore that.

If a text field: strWhere = "[ECMA]=' " & Me![EMCA] & " ' "


If a numeric field: strWhere = "[ECMA]=" & Me![txtEMCA]

HTH,
Gina Whipp


I have a Form and only want to print the Record that is displayed. On
the
Form I have a command button that opens up a report that is supposed
to
show
the current record. However, currently it is previewing all the
records
in
the database - the code for this is shown below . (The ECMA is the
unique
field)

Private Sub Command300_Click()
On Error GoTo Err_Command300_Click

Dim stDocName As String
Dim strWhere As String

strWhere = "[ECMA] = """ & Me.txtEMCA & """"

stDocName = "ProductDetails1"
DoCmd.OpenReport stDocName, acPreview, strWhere



Exit_Command300_Click:
Exit Sub

Err_Command300_Click:
MsgBox Err.Description
Resume Exit_Command300_Click

End Sub
 
Hi

the Record Source of the report is the Form. Some of the information comes
from a look up table thats why some fields are populated automatically when a
search is done by the unique number. Also I have a number of unbound text
boxes.

All I require to do is click a button which will show the form in Print
Preview mode and then display the information that the user has entered on
the form.
--
Thank you for your help


Gina Whipp said:
Okay, I have never done a report like that but I just did one to see what
happens. And I see it takes on the same Record Source as the form, so what
is the Record Source of the form? I also noticed that my calculated fields
(the ones located directly on the form show #Error). I also noticed that is
shows every record, so I fixed my button to just show me whatever record I
was previewing.

After doing all that, the source of your report is not the form but the
Record Source of the form, so once again, what is the Record Source of the
report? I know you can see the information on the form but something must
have changed which is why I want you to look at the Record Source of the
report.

I am not sure why it doesn't work either but might as well start with
obvious and move on from there.

Gina Whipp

Kirt84 said:
The source of the Report is the Form. I done a Save As on the Form and
saved
it in Report format. The fields on the Report are sourced from the Form -
not
sure why it doesn't work?
--
Thank you for your help


Gina Whipp said:
What is the source of the report? A query??? Take a look at the query,
can
you find the ECMA record in the query?

Thank you - this is now only previewing the one Record, however no
information is populated in the text boxes on the Report.
ECMA is the name of the field on the table and txtECMA is the name of
the
text box. The code I have put in is below:

Private Sub Command300_Click()
On Error GoTo Err_Command300_Click

Dim stDocName As String
Dim strWhere As String

strWhere = "[ECMA]=" & Me![EMCA]

stDocName = "ProductDetails1"
DoCmd.OpenReport "ProductDetails1", acViewPreview, , "[ECMA]=' " &
Me![txtEMCA] & " ' "



Exit_Command300_Click:
Exit Sub

Err_Command300_Click:
MsgBox Err.Description
Resume Exit_Command300_Click

End Sub


--
Thank you for your help


:

Kirt84,

I would use the below line...

Private Sub Command300_Click()
DoCmd.OpenReport "ProductDetails1", acViewPreview, , "[ECMA]=' "
&
Me![EMCA] & " ' "
End Sub

However, if you want to just fix the strWhere line then below should
do
it.
Also, you may need another comma after acPreview (so there would be 2
commas). I also noticed ECMA and then Me![txtEMCA], are they suppose
to
be
the same? If there are suppose to be different ignore that.

If a text field: strWhere = "[ECMA]=' " & Me![EMCA] & " ' "


If a numeric field: strWhere = "[ECMA]=" & Me![txtEMCA]

HTH,
Gina Whipp


I have a Form and only want to print the Record that is displayed. On
the
Form I have a command button that opens up a report that is supposed
to
show
the current record. However, currently it is previewing all the
records
in
the database - the code for this is shown below . (The ECMA is the
unique
field)

Private Sub Command300_Click()
On Error GoTo Err_Command300_Click

Dim stDocName As String
Dim strWhere As String

strWhere = "[ECMA] = """ & Me.txtEMCA & """"

stDocName = "ProductDetails1"
DoCmd.OpenReport stDocName, acPreview, strWhere



Exit_Command300_Click:
Exit Sub

Err_Command300_Click:
MsgBox Err.Description
Resume Exit_Command300_Click

End Sub
 
Kirt84,

Okay, maybe I am not being clear... There is a Record Source of something.
When you use a form for a report, as opposed to creating a report with a
query as a Record Source, there is still a Record Source. So what is the
Record Source of the form.

Also of note, unbound text or combo boxes will NOT print on your report made
from your form. (I can't get them to print on the the one I made, probably
one of many reasons I choose to use reports.)

So, my suggestion would would be to create a 'real' report from the report
wizard, if this is your first report. However, you should create a query
first to base your report on. HOWEVER, if you are determined to do this the
hard way, I still need to know a Record Source and the fields included in
the Record Source and the fields you want to show on your 'report'.

As I said, other than that I am at a loss as to why it's not working.

Gina Whipp


Kirt84 said:
Hi

the Record Source of the report is the Form. Some of the information comes
from a look up table thats why some fields are populated automatically
when a
search is done by the unique number. Also I have a number of unbound text
boxes.

All I require to do is click a button which will show the form in Print
Preview mode and then display the information that the user has entered on
the form.
--
Thank you for your help


Gina Whipp said:
Okay, I have never done a report like that but I just did one to see what
happens. And I see it takes on the same Record Source as the form, so
what
is the Record Source of the form? I also noticed that my calculated
fields
(the ones located directly on the form show #Error). I also noticed that
is
shows every record, so I fixed my button to just show me whatever record
I
was previewing.

After doing all that, the source of your report is not the form but the
Record Source of the form, so once again, what is the Record Source of
the
report? I know you can see the information on the form but something
must
have changed which is why I want you to look at the Record Source of the
report.

I am not sure why it doesn't work either but might as well start with
obvious and move on from there.

Gina Whipp

Kirt84 said:
The source of the Report is the Form. I done a Save As on the Form and
saved
it in Report format. The fields on the Report are sourced from the
Form -
not
sure why it doesn't work?
--
Thank you for your help


:

What is the source of the report? A query??? Take a look at the
query,
can
you find the ECMA record in the query?

Thank you - this is now only previewing the one Record, however no
information is populated in the text boxes on the Report.
ECMA is the name of the field on the table and txtECMA is the name
of
the
text box. The code I have put in is below:

Private Sub Command300_Click()
On Error GoTo Err_Command300_Click

Dim stDocName As String
Dim strWhere As String

strWhere = "[ECMA]=" & Me![EMCA]

stDocName = "ProductDetails1"
DoCmd.OpenReport "ProductDetails1", acViewPreview, , "[ECMA]=' " &
Me![txtEMCA] & " ' "



Exit_Command300_Click:
Exit Sub

Err_Command300_Click:
MsgBox Err.Description
Resume Exit_Command300_Click

End Sub


--
Thank you for your help


:

Kirt84,

I would use the below line...

Private Sub Command300_Click()
DoCmd.OpenReport "ProductDetails1", acViewPreview, , "[ECMA]='
"
&
Me![EMCA] & " ' "
End Sub

However, if you want to just fix the strWhere line then below
should
do
it.
Also, you may need another comma after acPreview (so there would be
2
commas). I also noticed ECMA and then Me![txtEMCA], are they
suppose
to
be
the same? If there are suppose to be different ignore that.

If a text field: strWhere = "[ECMA]=' " & Me![EMCA] & " ' "


If a numeric field: strWhere = "[ECMA]=" & Me![txtEMCA]

HTH,
Gina Whipp


I have a Form and only want to print the Record that is displayed.
On
the
Form I have a command button that opens up a report that is
supposed
to
show
the current record. However, currently it is previewing all the
records
in
the database - the code for this is shown below . (The ECMA is
the
unique
field)

Private Sub Command300_Click()
On Error GoTo Err_Command300_Click

Dim stDocName As String
Dim strWhere As String

strWhere = "[ECMA] = """ & Me.txtEMCA & """"

stDocName = "ProductDetails1"
DoCmd.OpenReport stDocName, acPreview, strWhere



Exit_Command300_Click:
Exit Sub

Err_Command300_Click:
MsgBox Err.Description
Resume Exit_Command300_Click

End Sub
 
Kirt,

The Record Source of a report can only be a table or a query. Here's
how to find/change it:

- Open the report in design view.
- Then open the Properties window (F4).
- Make sure it says "Report" at the top of the Properties window, so
you're seeing the properties of the report in general, and not one of
the controls on the report.
- If you click on the Data tab, the first property listed is the Record
Source.

This should be a table or query. Then for each of the controls in your
report, the Control Source property should be set to one of the fields
in the table or query that is the Record Source.

Jerry
 
Back
Top