Opening a Report to a Specific Record

  • Thread starter Thread starter PennyB
  • Start date Start date
P

PennyB

Can someone please tell me why this isn't working to open the Building Permit
(report) to one specific record? The report is based on a query that shows
all records for Job Number and Permit Number. There is about 685 records.

Here is the code I am using:

Private Sub cmdBuildingPermit_Click()

Dim strWhere As String

strWhere = "[JobNumber] = " & Me.JobNumber & ""
strWhere = "[PermitTaskNumber]=" & Me.PermitNumber & ""


DoCmd.OpenReport "rptBuildingPermit", acViewPreview, , strWhere

End Sub


What happens - I get a mess. I don't just get one record I get 495 and they
are in random order.

Thanks,

PennyB
 
Penny, I am not an expert like most who answer these questions.
But, why don't you try
strWhere = "[JobNumber] = " & Me.JobNumber & " AND
[PermitTaskNumber]=" & Me.PermitNumber
 
Can someone please tell me why this isn't working to open the Building Permit
(report) to one specific record? The report is based on a query that shows
all records for Job Number and Permit Number. There is about 685 records.

Here is the code I am using:

Private Sub cmdBuildingPermit_Click()

Dim strWhere As String

strWhere = "[JobNumber] = " & Me.JobNumber & ""
strWhere = "[PermitTaskNumber]=" & Me.PermitNumber & ""


DoCmd.OpenReport "rptBuildingPermit", acViewPreview, , strWhere

End Sub

What happens - I get a mess. I don't just get one record I get 495 and they
are in random order.

Thanks,

PennyB

strWhere = "[JobNumber] = " & Me.JobNumber & " AND
[PermitTaskNumber]=" & Me.PermitNumber
DoCmd.OpenReport "rptBuildingPermit", acViewPreview, , strWhere

The above assumes both JobNumber and PermitTaskNumber are Number
datatype fields.

As far as the records being in random order, the above has nothing to
do with the order of records in a report. To sort records in a report
you should use the report's sorting and grouping dialog.
 
Thanks, but that didn't work either.

JD said:
Penny, I am not an expert like most who answer these questions.
But, why don't you try
strWhere = "[JobNumber] = " & Me.JobNumber & " AND
[PermitTaskNumber]=" & Me.PermitNumber




PennyB said:
Can someone please tell me why this isn't working to open the Building Permit
(report) to one specific record? The report is based on a query that shows
all records for Job Number and Permit Number. There is about 685 records.

Here is the code I am using:

Private Sub cmdBuildingPermit_Click()

Dim strWhere As String

strWhere = "[JobNumber] = " & Me.JobNumber & ""
strWhere = "[PermitTaskNumber]=" & Me.PermitNumber & ""


DoCmd.OpenReport "rptBuildingPermit", acViewPreview, , strWhere

End Sub


What happens - I get a mess. I don't just get one record I get 495 and they
are in random order.

Thanks,

PennyB
 
They are both numbers. Also, I realize the sorting has nothing to do with
the code, but the funny thing is prior to putting the code in it was always
in number order by Job Number. I use to have the query ask for the job
number and permit number and that worked fine, but I want to make it easier
on the end user.

Thanks.

fredg said:
Can someone please tell me why this isn't working to open the Building Permit
(report) to one specific record? The report is based on a query that shows
all records for Job Number and Permit Number. There is about 685 records.

Here is the code I am using:

Private Sub cmdBuildingPermit_Click()

Dim strWhere As String

strWhere = "[JobNumber] = " & Me.JobNumber & ""
strWhere = "[PermitTaskNumber]=" & Me.PermitNumber & ""


DoCmd.OpenReport "rptBuildingPermit", acViewPreview, , strWhere

End Sub

What happens - I get a mess. I don't just get one record I get 495 and they
are in random order.

Thanks,

PennyB

strWhere = "[JobNumber] = " & Me.JobNumber & " AND
[PermitTaskNumber]=" & Me.PermitNumber
DoCmd.OpenReport "rptBuildingPermit", acViewPreview, , strWhere

The above assumes both JobNumber and PermitTaskNumber are Number
datatype fields.

As far as the records being in random order, the above has nothing to
do with the order of records in a report. To sort records in a report
you should use the report's sorting and grouping dialog.
 
Hi PennyB,
I think you are missing some single quotes around in the double quote.

strWhere = "[JobNumber] = ' " & Me.JobNumber & "'"
strWhere = "[PermitTaskNumber]= ' " & Me.PermitNumber & "'"

This is what I use in one of my codes:
stWhere = "[InvoiceNo] ='" & Me.cmbInvoiceNumber.Column(0) & "'"

Larry

PennyB said:
They are both numbers. Also, I realize the sorting has nothing to do with
the code, but the funny thing is prior to putting the code in it was always
in number order by Job Number. I use to have the query ask for the job
number and permit number and that worked fine, but I want to make it easier
on the end user.

Thanks.

fredg said:
Can someone please tell me why this isn't working to open the Building Permit
(report) to one specific record? The report is based on a query that shows
all records for Job Number and Permit Number. There is about 685 records.

Here is the code I am using:

Private Sub cmdBuildingPermit_Click()

Dim strWhere As String

strWhere = "[JobNumber] = " & Me.JobNumber & ""
strWhere = "[PermitTaskNumber]=" & Me.PermitNumber & ""


DoCmd.OpenReport "rptBuildingPermit", acViewPreview, , strWhere

End Sub

What happens - I get a mess. I don't just get one record I get 495 and they
are in random order.

Thanks,

PennyB

strWhere = "[JobNumber] = " & Me.JobNumber & " AND
[PermitTaskNumber]=" & Me.PermitNumber
DoCmd.OpenReport "rptBuildingPermit", acViewPreview, , strWhere

The above assumes both JobNumber and PermitTaskNumber are Number
datatype fields.

As far as the records being in random order, the above has nothing to
do with the order of records in a report. To sort records in a report
you should use the report's sorting and grouping dialog.
 
Back
Top