Generating A Report From a specific Record

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

Guest

Here is what I need help with before I rip my already thinning hair out.

In my business, We use access to enter customer orders into our system. I
have already generated a form for this, as well as the report that I would
like to print out. However. I need to learn how to generate a report that
will consist of JUST the record that I entered into the form. I would like
to create a Macro based on a command button that when clicked upon, It
generates the report and returns me to the main screen... Help me please
 
Here is the code I put behind my buttons when I want to do this....
(note: this is a very common question. Please search previous posts before
you submit a new thread. You can often find your answer that way.)




Button to print specific record
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.
 
How about if I wanted it to automatically send the report to an email address?

I am clueless with some aspects of this

Rick B said:
Here is the code I put behind my buttons when I want to do this....
(note: this is a very common question. Please search previous posts before
you submit a new thread. You can often find your answer that way.)




Button to print specific record
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.






--
Rick B



inertia said:
Here is what I need help with before I rip my already thinning hair out.

In my business, We use access to enter customer orders into our system. I
have already generated a form for this, as well as the report that I would
like to print out. However. I need to learn how to generate a report that
will consist of JUST the record that I entered into the form. I would like
to create a Macro based on a command button that when clicked upon, It
generates the report and returns me to the main screen... Help me please
 
Have you tried to llok at the help files? Have you looked at the sample
database "Northwinds"? Have you searched previous posts in this newsgroup?

Use the resources available and THEN ask us questions if you have specific
questions.

--
Rick B



inertia said:
How about if I wanted it to automatically send the report to an email address?

I am clueless with some aspects of this

Rick B said:
Here is the code I put behind my buttons when I want to do this....
(note: this is a very common question. Please search previous posts before
you submit a new thread. You can often find your answer that way.)




Button to print specific record
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.






--
Rick B



inertia said:
Here is what I need help with before I rip my already thinning hair out.

In my business, We use access to enter customer orders into our
system.
I
have already generated a form for this, as well as the report that I would
like to print out. However. I need to learn how to generate a report that
will consist of JUST the record that I entered into the form. I would like
to create a Macro based on a command button that when clicked upon, It
generates the report and returns me to the main screen... Help me
please
 
Back
Top