Form & Report

G

Guest

I have a form called Maintenance, when this form is filled in I can print the
Service Order for it. The Service Order is a report. I would like to be
able to fill in Maintenance ...say... 100 and in the Service Order report
print the same...100...
Now I have to go to print select pages to print...type in from...1...to...1
and am able to print the service order for Maintenance 100. Can someone help
me?
 
M

Marshall Barton

Holly said:
I have a form called Maintenance, when this form is filled in I can print the
Service Order for it. The Service Order is a report. I would like to be
able to fill in Maintenance ...say... 100 and in the Service Order report
print the same...100...
Now I have to go to print select pages to print...type in from...1...to...1
and am able to print the service order for Maintenance 100.

Add a button to the form to print/preview the report. Have
the wizard create the code, then modify it to use the
OpenReport method's WhereCondition argument something like:

stCriteria = "OrderID = " & Me.OrderID
DoCmd.OpentReport stDoc,acViewPreview, , stCriteria
 
G

Guest

Thanks Marshall, I am not sure I understand your instructions, but I will try
it and let you know.
 
G

Guest

Sorry Marshall, I tried...I guess I will those step by step instructions...do
you mind?
 
M

Marshall Barton

Sure, but I will need to see (Copy/Paste) the code you have
in the button's Click event procedure along with the name of
the table fields and form controls involved in the
operation.
 
G

Guest

Hi Marsh,

Thanks so much for hanging in there with me. Now, just how do I get you
this information...Copy/paste how?

Marshall Barton said:
Sure, but I will need to see (Copy/Paste) the code you have
in the button's Click event procedure along with the name of
the table fields and form controls involved in the
operation.
--
Marsh
MVP [MS Access]


Holly said:
Sorry Marshall, I tried...I guess I will those step by step instructions...do
you mind?
 
M

Marshall Barton

Open the form in design view. Double xlixk on the command
button to open its property sheet. Aelect the Event tab and
look down the list of events and click on the On Click event
property to highlight it. Then click on the builder button
(the one with 3 dots) over in the right margin. The VBE
window will open with the cursoe in the button's Click event
procedure. Drag the mouse from the Sub {buttonname}_Click()
line down to the End Sub line. Then use COPY on the Edit
menu. Go back to the window where you are composing your
reply and PASTE the code into the message.

The field name viewed double clicking on the text box bound
to the orders(?) field and looking at the Control Source
property. The text box's name is in its Name property.
 
G

Guest

Marsh...I deleted the button because I could not get it to work. I need help
from the button stage. (I am a tad bit old so this may take some
patience...however, I am cute)

Marshall Barton said:
Open the form in design view. Double xlixk on the command
button to open its property sheet. Aelect the Event tab and
look down the list of events and click on the On Click event
property to highlight it. Then click on the builder button
(the one with 3 dots) over in the right margin. The VBE
window will open with the cursoe in the button's Click event
procedure. Drag the mouse from the Sub {buttonname}_Click()
line down to the End Sub line. Then use COPY on the Edit
menu. Go back to the window where you are composing your
reply and PASTE the code into the message.

The field name viewed double clicking on the text box bound
to the orders(?) field and looking at the Control Source
property. The text box's name is in its Name property.
--
Marsh
MVP [MS Access]


Holly said:
Thanks so much for hanging in there with me. Now, just how do I get you
this information...Copy/paste how?
 
G

Guest

Private Sub Command62_Click()
On Error GoTo Err_Command62_Click

Dim stDocName As String

stCriteria = ServiceOrder.[ "&Me.ServiceOrders"]
DoCmd.OpenReport stDoc.acPreview.stCriteria

Exit_Command62_Click:
Exit Sub

Err_Command62_Click:
MsgBox Err.Description
Resume Exit_Command62_Click

End Sub


Holly C said:
Marsh...I deleted the button because I could not get it to work. I need help
from the button stage. (I am a tad bit old so this may take some
patience...however, I am cute)

Marshall Barton said:
Open the form in design view. Double xlixk on the command
button to open its property sheet. Aelect the Event tab and
look down the list of events and click on the On Click event
property to highlight it. Then click on the builder button
(the one with 3 dots) over in the right margin. The VBE
window will open with the cursoe in the button's Click event
procedure. Drag the mouse from the Sub {buttonname}_Click()
line down to the End Sub line. Then use COPY on the Edit
menu. Go back to the window where you are composing your
reply and PASTE the code into the message.

The field name viewed double clicking on the text box bound
to the orders(?) field and looking at the Control Source
property. The text box's name is in its Name property.
--
Marsh
MVP [MS Access]


Holly said:
Thanks so much for hanging in there with me. Now, just how do I get you
this information...Copy/paste how?

:

Sure, but I will need to see (Copy/Paste) the code you have
in the button's Click event procedure along with the name of
the table fields and form controls involved in the
operation.


Holly C wrote:

Sorry Marshall, I tried...I guess I will those step by step instructions...do
you mind?

:

Thanks Marshall, I am not sure I understand your instructions, but I will try
it and let you know.

:

Holly C wrote:

I have a form called Maintenance, when this form is filled in I can print the
Service Order for it. The Service Order is a report. I would like to be
able to fill in Maintenance ...say... 100 and in the Service Order report
print the same...100...
Now I have to go to print select pages to print...type in from...1...to...1
and am able to print the service order for Maintenance 100.

Add a button to the form to print/preview the report. Have
the wizard create the code, then modify it to use the
OpenReport method's WhereCondition argument something like:

stCriteria = "OrderID = " & Me.OrderID
DoCmd.OpentReport stDoc,acViewPreview, , stCriteria
 
M

Marshall Barton

Holly said:
Private Sub Command62_Click()
On Error GoTo Err_Command62_Click

Dim stDocName As String

stCriteria = ServiceOrder.[ "&Me.ServiceOrders"]
DoCmd.OpenReport stDoc.acPreview.stCriteria

Exit_Command62_Click:
Exit Sub

Err_Command62_Click:
MsgBox Err.Description
Resume Exit_Command62_Click

End Sub


My goodness, where did that come from? It sort of looks
like a little like what the wizard would generate, but there
are so many errors I can't see that as the cause. If you
retyped the code, then I guess all those syntax errors are
typos, which is why I asked you to Copy/Paste the code.

I still don't know the name of the field in the table, maybe
it's ServiceOrder?

Let's try something more like:

Private Sub Command62_Click()
Dim stDocName As String
Dim stCriteria As String

On Error GoTo Err_Command62_Click

stDocName = "put the name of the report here"
stCriteria = "ServiceOrder = " & Me.ServiceOrder
DoCmd.OpenReport stDocName, acPreview, , stCriteria

Exit_Command62_Click:
Exit Sub

Err_Command62_Click:
MsgBox Err.Description
Resume Exit_Command62_Click
End Sub
 
G

Guest

Hi Marsh,

I tried to follow what you told me before. Anyway do I use the name of the
report for the button or the name of the field ServiceOrderNumber which is
auto number.
I would like the form Maintenance to print the report for the
ServiceOrderNumber the form creates.
Holly

Marshall Barton said:
Holly said:
Private Sub Command62_Click()
On Error GoTo Err_Command62_Click

Dim stDocName As String

stCriteria = ServiceOrder.[ "&Me.ServiceOrders"]
DoCmd.OpenReport stDoc.acPreview.stCriteria

Exit_Command62_Click:
Exit Sub

Err_Command62_Click:
MsgBox Err.Description
Resume Exit_Command62_Click

End Sub


My goodness, where did that come from? It sort of looks
like a little like what the wizard would generate, but there
are so many errors I can't see that as the cause. If you
retyped the code, then I guess all those syntax errors are
typos, which is why I asked you to Copy/Paste the code.

I still don't know the name of the field in the table, maybe
it's ServiceOrder?

Let's try something more like:

Private Sub Command62_Click()
Dim stDocName As String
Dim stCriteria As String

On Error GoTo Err_Command62_Click

stDocName = "put the name of the report here"
stCriteria = "ServiceOrder = " & Me.ServiceOrder
DoCmd.OpenReport stDocName, acPreview, , stCriteria

Exit_Command62_Click:
Exit Sub

Err_Command62_Click:
MsgBox Err.Description
Resume Exit_Command62_Click
End Sub
 
G

Guest

This is what it says. I printed down your statement and the button would not
work. So I am doing something wrong. Do you put the name of the report
where it says st.DocName?

Private Sub Command39_Click()
On Error GoTo Err_Command39_Click

Dim stDocName As String

stDocName = "Service Orders"
DoCmd.OpenReport stDocName, acPreview

Exit_Command39_Click:
Exit Sub

Err_Command39_Click:
MsgBox Err.Description
Resume Exit_Command39_Click

End Sub


Marshall Barton said:
Holly said:
Private Sub Command62_Click()
On Error GoTo Err_Command62_Click

Dim stDocName As String

stCriteria = ServiceOrder.[ "&Me.ServiceOrders"]
DoCmd.OpenReport stDoc.acPreview.stCriteria

Exit_Command62_Click:
Exit Sub

Err_Command62_Click:
MsgBox Err.Description
Resume Exit_Command62_Click

End Sub


My goodness, where did that come from? It sort of looks
like a little like what the wizard would generate, but there
are so many errors I can't see that as the cause. If you
retyped the code, then I guess all those syntax errors are
typos, which is why I asked you to Copy/Paste the code.

I still don't know the name of the field in the table, maybe
it's ServiceOrder?

Let's try something more like:

Private Sub Command62_Click()
Dim stDocName As String
Dim stCriteria As String

On Error GoTo Err_Command62_Click

stDocName = "put the name of the report here"
stCriteria = "ServiceOrder = " & Me.ServiceOrder
DoCmd.OpenReport stDocName, acPreview, , stCriteria

Exit_Command62_Click:
Exit Sub

Err_Command62_Click:
MsgBox Err.Description
Resume Exit_Command62_Click
End Sub
 
G

Guest

Hi Marsh,

The button works, it brings up the report. However, I would like it to
preview the current report. When the Maintenance form generates Service
Order Number 293 I would like the Service Orders report to preview 293. Can
I do this?
Holly

Holly C said:
This is what it says. I printed down your statement and the button would not
work. So I am doing something wrong. Do you put the name of the report
where it says st.DocName?

Private Sub Command39_Click()
On Error GoTo Err_Command39_Click

Dim stDocName As String

stDocName = "Service Orders"
DoCmd.OpenReport stDocName, acPreview

Exit_Command39_Click:
Exit Sub

Err_Command39_Click:
MsgBox Err.Description
Resume Exit_Command39_Click

End Sub


Marshall Barton said:
Holly said:
Private Sub Command62_Click()
On Error GoTo Err_Command62_Click

Dim stDocName As String

stCriteria = ServiceOrder.[ "&Me.ServiceOrders"]
DoCmd.OpenReport stDoc.acPreview.stCriteria

Exit_Command62_Click:
Exit Sub

Err_Command62_Click:
MsgBox Err.Description
Resume Exit_Command62_Click

End Sub


My goodness, where did that come from? It sort of looks
like a little like what the wizard would generate, but there
are so many errors I can't see that as the cause. If you
retyped the code, then I guess all those syntax errors are
typos, which is why I asked you to Copy/Paste the code.

I still don't know the name of the field in the table, maybe
it's ServiceOrder?

Let's try something more like:

Private Sub Command62_Click()
Dim stDocName As String
Dim stCriteria As String

On Error GoTo Err_Command62_Click

stDocName = "put the name of the report here"
stCriteria = "ServiceOrder = " & Me.ServiceOrder
DoCmd.OpenReport stDocName, acPreview, , stCriteria

Exit_Command62_Click:
Exit Sub

Err_Command62_Click:
MsgBox Err.Description
Resume Exit_Command62_Click
End Sub
 
M

Marshall Barton

It looks like you're making some progress. At least the
wizard's code makes sense now. Unfortunately, you forgot to
modify it as I suggested in an earlier reply:

Private Sub Command39_Click()
On Error GoTo Err_Command39_Click

Dim stDocName As String
If Me.Dirty Then Me.Dirty = False

stDocName = "Service Orders"
stCriteria = "ServiceOrderNumber = " _
& Me.ServiceOrderNumber
DoCmd.OpenReport stDocName, acPreview, , stCriteria

Exit_Command39_Click:
Exit Sub

Err_Command39_Click:
MsgBox Err.Description
Resume Exit_Command39_Click
End Sub

stDocName (no period) is a string variable that you are
assigning the name of the Report (in the database window).
In the above code, it's Service Orders.

The name of the primary key field in the table is
ServiceOrderNumber in the above code.

If I have misunderstood you about either of those names,
change the code to use the actual names that you have.

Note that I added the line If Me.Dirty ... This line will
make sure that any edits to the current record in the form
are saved back to the table so the report can retrieve the
latest data.
--
Marsh
MVP [MS Access]


Holly said:
The button works, it brings up the report. However, I would like it to
preview the current report. When the Maintenance form generates Service
Order Number 293 I would like the Service Orders report to preview 293. Can
I do this?
Holly

Holly C said:
This is what it says. I printed down your statement and the button would not
work. So I am doing something wrong. Do you put the name of the report
where it says st.DocName?

Private Sub Command39_Click()
On Error GoTo Err_Command39_Click

Dim stDocName As String

stDocName = "Service Orders"
DoCmd.OpenReport stDocName, acPreview

Exit_Command39_Click:
Exit Sub

Err_Command39_Click:
MsgBox Err.Description
Resume Exit_Command39_Click

End Sub


Marshall Barton said:
Holly C wrote:
Private Sub Command62_Click()
On Error GoTo Err_Command62_Click

Dim stDocName As String

stCriteria = ServiceOrder.[ "&Me.ServiceOrders"]
DoCmd.OpenReport stDoc.acPreview.stCriteria

Exit_Command62_Click:
Exit Sub

Err_Command62_Click:
MsgBox Err.Description
Resume Exit_Command62_Click

End Sub


My goodness, where did that come from? It sort of looks
like a little like what the wizard would generate, but there
are so many errors I can't see that as the cause. If you
retyped the code, then I guess all those syntax errors are
typos, which is why I asked you to Copy/Paste the code.

I still don't know the name of the field in the table, maybe
it's ServiceOrder?

Let's try something more like:

Private Sub Command62_Click()
Dim stDocName As String
Dim stCriteria As String

On Error GoTo Err_Command62_Click

stDocName = "put the name of the report here"
stCriteria = "ServiceOrder = " & Me.ServiceOrder
DoCmd.OpenReport stDocName, acPreview, , stCriteria

Exit_Command62_Click:
Exit Sub

Err_Command62_Click:
MsgBox Err.Description
Resume Exit_Command62_Click
End Sub
 

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