Trouble with command button

M

Mya48

I have a form that customers use to place orders for office supplies. On
this form there's a button to preview the order which opens up a report that
lists their entire order. I also have a command button that says "place
order" and when clicked it sends me an email of the order. The problem I'm
having is that when I go to a different record old or new and press the
"place order" button, it remembers the last order it sent me not what's
currently on the form. How would I fix this? I don't know if it's related to
the code I have on the preview order button:

Private Sub PreviewPlacedOrder_Click()

Dim strReportName As String
Dim strCriteria As String

If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = "Placed Orders"
strCriteria = "[Order Number]= " & Me![Order Number]
'strCriteria = "[Order Number]='" & Me![Order Number] & "'"

DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
End If
End Sub

or

if it's the macro for the "place order" button which is simply to email me a
snapshot of the preview order report. I appreciate all your help.
 
A

Allen Browne

Suggestions:

1. Make sure the report is not already open (not even in design view.)
Otherwise the OpenReport won't work.

2. Try saving the current record before opening the report.

If Me.Dirty Then Me.Dirty = False
If CurrentProject.AllReports("Placed Orders").IsLoaded Then
DoCmd.Close acReport, "Placed Orders"
End If

As to whether to add the extra quotes or not, open your table in Design
view, and look at the Data Type column beside the Order Number field. If it
says Number, omit the quotes; if it says Text, include them.
 
M

Mya48

Thank you for your reply unfortunately it didn't work for me. It continues
to send me the last order I previewed. The only way it sends me what I want
is if I preview the order first and then click the place order button. Some
of my customers don't want to preview the order, they simply want to place an
order.

Allen Browne said:
Suggestions:

1. Make sure the report is not already open (not even in design view.)
Otherwise the OpenReport won't work.

2. Try saving the current record before opening the report.

If Me.Dirty Then Me.Dirty = False
If CurrentProject.AllReports("Placed Orders").IsLoaded Then
DoCmd.Close acReport, "Placed Orders"
End If

As to whether to add the extra quotes or not, open your table in Design
view, and look at the Data Type column beside the Order Number field. If it
says Number, omit the quotes; if it says Text, include them.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Mya48 said:
I have a form that customers use to place orders for office supplies. On
this form there's a button to preview the order which opens up a report
that
lists their entire order. I also have a command button that says "place
order" and when clicked it sends me an email of the order. The problem
I'm
having is that when I go to a different record old or new and press the
"place order" button, it remembers the last order it sent me not what's
currently on the form. How would I fix this? I don't know if it's related
to
the code I have on the preview order button:

Private Sub PreviewPlacedOrder_Click()

Dim strReportName As String
Dim strCriteria As String

If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = "Placed Orders"
strCriteria = "[Order Number]= " & Me![Order Number]
'strCriteria = "[Order Number]='" & Me![Order Number] & "'"

DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
End If
End Sub

or

if it's the macro for the "place order" button which is simply to email me
a
snapshot of the preview order report. I appreciate all your help.
 
A

Allen Browne

That's very odd.

Make sure you have the latest serice packs applied.
And make sure the focus has left the text box (so it gets updated.)

Unfortunately, I'll be unable to contribute further for 2 weeks.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.
Mya48 said:
Thank you for your reply unfortunately it didn't work for me. It
continues
to send me the last order I previewed. The only way it sends me what I
want
is if I preview the order first and then click the place order button.
Some
of my customers don't want to preview the order, they simply want to place
an
order.

Allen Browne said:
Suggestions:

1. Make sure the report is not already open (not even in design view.)
Otherwise the OpenReport won't work.

2. Try saving the current record before opening the report.

If Me.Dirty Then Me.Dirty = False
If CurrentProject.AllReports("Placed Orders").IsLoaded Then
DoCmd.Close acReport, "Placed Orders"
End If

As to whether to add the extra quotes or not, open your table in Design
view, and look at the Data Type column beside the Order Number field. If
it
says Number, omit the quotes; if it says Text, include them.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Mya48 said:
I have a form that customers use to place orders for office supplies.
On
this form there's a button to preview the order which opens up a report
that
lists their entire order. I also have a command button that says
"place
order" and when clicked it sends me an email of the order. The problem
I'm
having is that when I go to a different record old or new and press the
"place order" button, it remembers the last order it sent me not what's
currently on the form. How would I fix this? I don't know if it's
related
to
the code I have on the preview order button:

Private Sub PreviewPlacedOrder_Click()

Dim strReportName As String
Dim strCriteria As String

If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = "Placed Orders"
strCriteria = "[Order Number]= " & Me![Order Number]
'strCriteria = "[Order Number]='" & Me![Order Number] & "'"

DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
End If
End Sub

or

if it's the macro for the "place order" button which is simply to email
me
a
snapshot of the preview order report. I appreciate all your help.
 

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