Need to produce report for current form entry

N

Narwe

I need to create a report that displays data only from the form entry I am currently viewing.I was thinking that I would attach a button to the form to perform this function.

I'm not sure where to start with this problem. . . Anybody got any vb tips/leads?
 
F

fredg

I need to create a report that displays data only from the form entry I am currently viewing.I was thinking that I would attach a button to the form to perform this function.

I'm not sure where to start with this problem. . . Anybody got any vb tips/leads?

Your table should have a unique prime key field.

If so, code the command button's Click event:
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]

The above assumes a [RecordID] field that is a Number Datatype.

If [RecordID] is Text Datatype, then use:

"[RecordID] = '" & [RecordID] & "'"

as the Where clause.
Change the [RecordID] field name to whatever the actual field name is
that you are using.

See Access Help files for:
Restrict + Restrict data to a subset of records
 
R

Reggie

You could also use something like this placed in the On Open event of your
report.

'Use this if the source is on the main form
Private Sub Report_Open(Cancel As Integer)
Me.RecordSource = Forms![MyFormMain].Form.RecordSource

With Forms![MyFormMain].Form
If .OrderByOn Then
Me.OrderBy = .OrderBy
Me.OrderByOn = True
End If
If .FilterOn Then
Me.Filter = .Filter
Me.FilterOn = True
End If
End With

End Sub



'Use this if the source is from a subform
Private Sub Report_Open(Cancel As Integer)
Me.RecordSource = Forms![MyFormMain]![MySubForm].Form.RecordSource

With Forms![MyFormMain]![MySubForm].Form
If .OrderByOn Then
Me.OrderBy = .OrderBy
Me.OrderByOn = True
End If
If .FilterOn Then
Me.Filter = .Filter
Me.FilterOn = True
End If
End With

End Sub


--
Reggie

----------
am currently viewing.I was thinking that I would attach a button to the form
to perform this function.
I'm not sure where to start with this problem. . . Anybody got any vb
tips/leads?

Your table should have a unique prime key field.

If so, code the command button's Click event:
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]

The above assumes a [RecordID] field that is a Number Datatype.

If [RecordID] is Text Datatype, then use:

"[RecordID] = '" & [RecordID] & "'"

as the Where clause.
Change the [RecordID] field name to whatever the actual field name is
that you are using.

See Access Help files for:
Restrict + Restrict data to a subset of records
 
N

Narwe

thank you both for your help :)

Reggie said:
You could also use something like this placed in the On Open event of your
report.

'Use this if the source is on the main form
Private Sub Report_Open(Cancel As Integer)
Me.RecordSource = Forms![MyFormMain].Form.RecordSource

With Forms![MyFormMain].Form
If .OrderByOn Then
Me.OrderBy = .OrderBy
Me.OrderByOn = True
End If
If .FilterOn Then
Me.Filter = .Filter
Me.FilterOn = True
End If
End With

End Sub



'Use this if the source is from a subform
Private Sub Report_Open(Cancel As Integer)
Me.RecordSource = Forms![MyFormMain]![MySubForm].Form.RecordSource

With Forms![MyFormMain]![MySubForm].Form
If .OrderByOn Then
Me.OrderBy = .OrderBy
Me.OrderByOn = True
End If
If .FilterOn Then
Me.Filter = .Filter
Me.FilterOn = True
End If
End With

End Sub


--
Reggie

----------
am currently viewing.I was thinking that I would attach a button to the form
to perform this function.
I'm not sure where to start with this problem. . . Anybody got any vb
tips/leads?

Your table should have a unique prime key field.

If so, code the command button's Click event:
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]

The above assumes a [RecordID] field that is a Number Datatype.

If [RecordID] is Text Datatype, then use:

"[RecordID] = '" & [RecordID] & "'"

as the Where clause.
Change the [RecordID] field name to whatever the actual field name is
that you are using.

See Access Help files for:
Restrict + Restrict data to a subset of records
 

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

Top