Sort Report By ID

  • Thread starter Thread starter Jone
  • Start date Start date
J

Jone

Hi,
I have a form and a command button that opens a report, how can I make that
the report should only open for that MemberID that’s currently open in my
form, for example the MemberID is 376 then the report 376 should open.
 
Can you please specify the code exactly how I should write it? Also, will
this work even the MemberID is not on focus?
 
It does not work this is what i wrote

Private Sub PrintCurrentRecord_Click()
If Me.Dirty Then Me.Dirty = False
DoCmd.OpenReport "BillForLimudim", acViewNormal, _
WhereCondition:="AccountID=""" & Me.AccountID & """"
End Sub

And when i press that button I get this error

runtime error 3464
Data type mismatch in criteria expression.

Please help!

Marshall Barton said:
It doesn't matter which control has the focus, but it does
require that the current record be the one you want the
report to display.

I can not write the exact code without knowing what you have
on your existing OpenReport statement. In general, all you
need is to add a space and underscore to end of your
existing OpenReport line and put the WhereCondition stuff on
the next line. If the name in the form is different, change
the name after Me. to your name. Replace the member id name
inside the quotes to the name of the field in the report's
record source.

If the member id field in the report is a Text field, then
the additional line should be like:
WhereCondition:= "MemberID=""" & Me.MemberID & """"

If the report;s record source is based on the same table as
the form, then you need to make sure any changes to the
current record are saved to the tabl before opening the
report. Insert this exact line before the OpenReport line:

If Me.Dirty Then Me.Dirty = False

That covers every thing I can guess at. If you have
problems with it, post back with the information I need to.
--
Marsh
MVP [MS Access]

Can you please specify the code exactly how I should write it? Also, will
this work even the MemberID is not on focus?
 
It does not work this is what i wrote

Private Sub PrintCurrentRecord_Click()
If Me.Dirty Then Me.Dirty = False
DoCmd.OpenReport "BillForLimudim", acViewNormal, _
WhereCondition:="AccountID=""" & Me.AccountID & """"
End Sub

And when i press that button I get this error

runtime error 3464
Data type mismatch in criteria expression.

Please help!

Marshall Barton said:
It doesn't matter which control has the focus, but it does
require that the current record be the one you want the
report to display.

I can not write the exact code without knowing what you have
on your existing OpenReport statement. In general, all you
need is to add a space and underscore to end of your
existing OpenReport line and put the WhereCondition stuff on
the next line. If the name in the form is different, change
the name after Me. to your name. Replace the member id name
inside the quotes to the name of the field in the report's
record source.

If the member id field in the report is a Text field, then
the additional line should be like:
WhereCondition:= "MemberID=""" & Me.MemberID & """"

If the report;s record source is based on the same table as
the form, then you need to make sure any changes to the
current record are saved to the tabl before opening the
report. Insert this exact line before the OpenReport line:

If Me.Dirty Then Me.Dirty = False

That covers every thing I can guess at. If you have
problems with it, post back with the information I need to.
--
Marsh
MVP [MS Access]
Can you please specify the code exactly how I should write it? Also, will
this work even the MemberID is not on focus?

:
Modify the button's code to use the OpenReport method's
WhereCondition argument:

DoCmd.OpenReport ... , _
WhereCondition:= "MemberID=" & Me.MemberID

Jone wrote:
I have a form and a command button that opens a report, how can I make that
the report should only open for that MemberID that¢s currently open in my
form, for example the MemberID is 376 then the report 376 should open.

It would seem your AccountID field is a Number datatype, not text
(re-read Marshall's reply).

If AccountID is indeed a Number datatype, then use
WhereCondition:="AccountID=" & Me.AccountID
 
Yes it is an autonumber so what do I have to do?

fredg said:
It does not work this is what i wrote

Private Sub PrintCurrentRecord_Click()
If Me.Dirty Then Me.Dirty = False
DoCmd.OpenReport "BillForLimudim", acViewNormal, _
WhereCondition:="AccountID=""" & Me.AccountID & """"
End Sub

And when i press that button I get this error

runtime error 3464
Data type mismatch in criteria expression.

Please help!

Marshall Barton said:
It doesn't matter which control has the focus, but it does
require that the current record be the one you want the
report to display.

I can not write the exact code without knowing what you have
on your existing OpenReport statement. In general, all you
need is to add a space and underscore to end of your
existing OpenReport line and put the WhereCondition stuff on
the next line. If the name in the form is different, change
the name after Me. to your name. Replace the member id name
inside the quotes to the name of the field in the report's
record source.

If the member id field in the report is a Text field, then
the additional line should be like:
WhereCondition:= "MemberID=""" & Me.MemberID & """"

If the report;s record source is based on the same table as
the form, then you need to make sure any changes to the
current record are saved to the tabl before opening the
report. Insert this exact line before the OpenReport line:

If Me.Dirty Then Me.Dirty = False

That covers every thing I can guess at. If you have
problems with it, post back with the information I need to.
--
Marsh
MVP [MS Access]

Jone wrote:
Can you please specify the code exactly how I should write it? Also, will
this work even the MemberID is not on focus?

:
Modify the button's code to use the OpenReport method's
WhereCondition argument:

DoCmd.OpenReport ... , _
WhereCondition:= "MemberID=" & Me.MemberID

Jone wrote:
I have a form and a command button that opens a report, how can I make that
the report should only open for that MemberID thatʼs currently open in my
form, for example the MemberID is 376 then the report 376 should open.

It would seem your AccountID field is a Number datatype, not text
(re-read Marshall's reply).

If AccountID is indeed a Number datatype, then use
WhereCondition:="AccountID=" & Me.AccountID
 
Back
Top