Opening Report From Form

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

Guest

I have button on a form that opens up a report, is there any way to have the
report open with the current record that's on the form? I have Auto number
field on the form, but I don't want the user to have to type the number in to
open the report to that record, I want the report to open with the current
record automatically. Thanks in advance.
 
Private Sub cmdPrint_Click()

Dim strWhere As String

If Me.Dirty Then 'Save any edits.

Me.Dirty = False

End If

If Me.NewRecord Then 'Check there is a record to print

MsgBox "Select a record to print"

Else

strWhere = "[ID] = " & Me.[ID]

DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

End If

End Sub



Notes: If your primary key is a Text type field (not a Number type field),
you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"

If you want the report to print without preview, replace acViewPreview with
acViewNormal.



See also: http://allenbrowne.com/casu-15.html



Please note, this is asked and answered all the time. In the future, I'd
suggest you search for your answers before posting a new thread. The
easiest way I have found is to go to www.google.com, click the "groups"
option, and enter a search string similar to the following...



microsoft.public.access report current record
 
You can use the WhereCondition parameter of docmd.openreport:

docmd.OpenReport "rptMyReport",,,"PKid=" & me.pkid
 
Thank You!

Sandra Daigle said:
You can use the WhereCondition parameter of docmd.openreport:

docmd.OpenReport "rptMyReport",,,"PKid=" & me.pkid

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

I have button on a form that opens up a report, is there any way to
have the report open with the current record that's on the form? I
have Auto number field on the form, but I don't want the user to have
to type the number in to open the report to that record, I want the
report to open with the current record automatically. Thanks in
advance.
 
Will Do! Thank You.

Rick B said:
Private Sub cmdPrint_Click()

Dim strWhere As String

If Me.Dirty Then 'Save any edits.

Me.Dirty = False

End If

If Me.NewRecord Then 'Check there is a record to print

MsgBox "Select a record to print"

Else

strWhere = "[ID] = " & Me.[ID]

DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

End If

End Sub



Notes: If your primary key is a Text type field (not a Number type field),
you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"

If you want the report to print without preview, replace acViewPreview with
acViewNormal.



See also: http://allenbrowne.com/casu-15.html



Please note, this is asked and answered all the time. In the future, I'd
suggest you search for your answers before posting a new thread. The
easiest way I have found is to go to www.google.com, click the "groups"
option, and enter a search string similar to the following...



microsoft.public.access report current record


--
Rick B




Dryder said:
I have button on a form that opens up a report, is there any way to have
the
report open with the current record that's on the form? I have Auto number
field on the form, but I don't want the user to have to type the number in
to
open the report to that record, I want the report to open with the current
record automatically. Thanks in advance.
 
Hi Rick,

I need your help. My situation is very similar to this post.

The way I have my form setup is to prompt the user for 5 different criteria.
Of course, the more criteria the user types in the form will show less and
less records (vs. just one criterion). Therefore, I want my report to print
what the form has.

The code on this report would only print based on one criterion which means
the report will print more records than the form has.

I do have a field for autonumber. If I use that in the code, I would get
only one record on my report. The autonumber field is not one of my criteria.

fyi - Out of 5 criteria, 3 are text and 2 are number.

I tried the code below, and it didn't work.

strWhere = "[ID] = " & Me.[ID] _
and "[Text]=""" & me.[Text] & """"

Thanks.


Rick B said:
Private Sub cmdPrint_Click()

Dim strWhere As String

If Me.Dirty Then 'Save any edits.

Me.Dirty = False

End If

If Me.NewRecord Then 'Check there is a record to print

MsgBox "Select a record to print"

Else

strWhere = "[ID] = " & Me.[ID]

DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

End If

End Sub



Notes: If your primary key is a Text type field (not a Number type field),
you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"

If you want the report to print without preview, replace acViewPreview with
acViewNormal.



See also: http://allenbrowne.com/casu-15.html



Please note, this is asked and answered all the time. In the future, I'd
suggest you search for your answers before posting a new thread. The
easiest way I have found is to go to www.google.com, click the "groups"
option, and enter a search string similar to the following...



microsoft.public.access report current record


--
Rick B




Dryder said:
I have button on a form that opens up a report, is there any way to have
the
report open with the current record that's on the form? I have Auto number
field on the form, but I don't want the user to have to type the number in
to
open the report to that record, I want the report to open with the current
record automatically. Thanks in advance.
 
Back
Top