Need to produce report for current form entry

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

Guest

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?
 
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
 
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
 
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
 
Back
Top