Access crashes with report preview command button

S

Sammie

I have a command button on a form which previews a report based on the form.
If the user has just entered data in any field on the form and then goes
directly to the command button, Access crashes, with the error message:
"Microsoft Office Access has encountered a problem and needs to close. We
are sorry for the inconvenience." I have learned that if my user simply
clicks in any other field after entering data but before pressing the command
button, that their changes are "saved" and they can prevent the crash.
Because it seems to occur after data entry into any of the form's fields, and
because it is very hard to consistently train users to click elsewhere before
pressing the command button, is there a way to save the record as part of the
code on the report preview command button? I'm not sure if the crash is
caused by something in my command button code or in the user situation I just
described above. Any suggestions on how to prevent this crash? I report the
error to Microsoft every time, but so far, no solution is being returned.

Below is the code on my print preview command button.
--
Thanks.
Sammie SBS 2003, OFFICE 2003, XP-PRO-SP3, IE7

** Report preview command button code **
Private Sub InvoiceS_Click()
On Error GoTo Err_InvoiceS_Click

If Me.Dirty Then
Me.Dirty = False
End If

'If this invoice has been customized, send a message to that effect to the
user, and exit the sub.
If [Customize this invoice] = 0 Then
'Don't customize. Proceed to the regular invoice.
Else
If [Customize this invoice] = 1 Then 'Customize. Refer the customer to
the customized invoice.
Dim strMessage As String
Dim dbsSuperdatabase As Database
Dim rstManufacturers As DAO.Recordset
strMessage = "This invoice has been customized. Do you want to print
the invoice from there?"
If YesNo(strMessage) Then
CustomLine1FOB.SetFocus
Exit Sub
End If
End If
End If

'Before previewing the invoice, update all the information.

'Post Total CIP to the shipments table.
'Shipments = Invoices Qry
Me![TotCIP] = Me![TotalCIP]

'Be sure the country field is filled in.
If IsNull(Destination) Then
'Dim strMessage As String
'Dim dbsSuperdatabase As Database
strMessage = "A destination country is required. Do you want to do that now?"
If YesNo(strMessage) Then
Destination.SetFocus
Exit Sub
End If
End If

'Post the invoice terms to the invoice
If IsNull(InvoiceTerms) Then
If Not IsNull(Sold_To) Then
If Not IsNull(CcTerms) Then
InvoiceTerms = CcTerms
Else
MsgBox "The invoice requires terms. First check that you have
the customer from the drop-down box. Then enter the customer default terms.
When you click on 'invoice' the terms will automatically populate."
ClientClientTerms.SetFocus
Exit Sub
End If
Else
If IsNull(CcTerms) Then
If Not IsNull(ClientTerms) Then
InvoiceTerms = ClientTerms
Else
MsgBox "The invoice requires terms. First check that you have
the customer from the drop-down box. Then enter the customer default terms.
When you click on 'invoice' the terms will automatically populate."
ClientTerms.SetFocus
Exit Sub
End If
End If
End If
End If

Me.REFRESH
'Verify that someone's name is on theinvoice.
If EmployeeID = 0 Then
MsgBox "Please enter the name of the person who will sign the invoice."
EmployeeID.SetFocus
Exit Sub
End If

If IsNull(EmployeeID) Then
MsgBox "Please enter the name of the person who will sign the invoice."
EmployeeID.SetFocus
Exit Sub
End If

'Verify that ship type has been specified.
If ShipType = 0 Then
strMessage = "A ship type is required. Do you want to do that now?"
If YesNo(strMessage) Then
ShipTypeOption.SetFocus
Exit Sub
End If
End If

'Verify that there is a sold to address:
If IsNull(SoldToAddress) Then
strMessage = "A SOLD TO address is required. Do you want to do that now?"
If YesNo(strMessage) Then
SoldToName.SetFocus
Exit Sub
End If
End If

'Verify that there is a shipto address.
If IsNull(ShipAddress) Then
If ShipCompany <> "TO BE DETERMINED" Then
strMessage = "A SHIP TO address is required. Do you want to do that now?"
If YesNo(strMessage) Then
ShipCompany.SetFocus
Exit Sub
Else
End If
End If
End If

'Make sure the record is saved before editing the invoice address
'put at beginning of procedure.
'If Me.Dirty Then Me.Dirty = False 'save any main form changes before moving
to the rfq subform

'Open the report. Filter sends it to either Invoice or InvoiceLava

Dim stDocName As String
stDocName = "Invoice"
' Print Invoice report, using Invoices Filter query to print
' invoice for current order.
DoCmd.OpenReport stDocName, acPreview, "qryInvoiceFilter"

Exit_InvoiceS_Click:
Exit Sub

Err_InvoiceS_Click:
MsgBox Err.Description
Resume Exit_InvoiceS_Click

End Sub
 
M

Maurice

Sammie,

I would have reccomended the me.dirty but saw that you already added that to
your code. Sometimes it helps to just delete the commandbutton, compact and
repair your db and then place a new button on the form again. Ofcourse you
copy your code first notepade or some other editor before deleting the
button. Paste your code again behind the new button. Before trying the new
button compact and repair again.

See if that might be of some help, long shot but if you don't try you don't
know.
--
Maurice Ausum


Sammie said:
I have a command button on a form which previews a report based on the form.
If the user has just entered data in any field on the form and then goes
directly to the command button, Access crashes, with the error message:
"Microsoft Office Access has encountered a problem and needs to close. We
are sorry for the inconvenience." I have learned that if my user simply
clicks in any other field after entering data but before pressing the command
button, that their changes are "saved" and they can prevent the crash.
Because it seems to occur after data entry into any of the form's fields, and
because it is very hard to consistently train users to click elsewhere before
pressing the command button, is there a way to save the record as part of the
code on the report preview command button? I'm not sure if the crash is
caused by something in my command button code or in the user situation I just
described above. Any suggestions on how to prevent this crash? I report the
error to Microsoft every time, but so far, no solution is being returned.

Below is the code on my print preview command button.
--
Thanks.
Sammie SBS 2003, OFFICE 2003, XP-PRO-SP3, IE7

** Report preview command button code **
Private Sub InvoiceS_Click()
On Error GoTo Err_InvoiceS_Click

If Me.Dirty Then
Me.Dirty = False
End If

'If this invoice has been customized, send a message to that effect to the
user, and exit the sub.
If [Customize this invoice] = 0 Then
'Don't customize. Proceed to the regular invoice.
Else
If [Customize this invoice] = 1 Then 'Customize. Refer the customer to
the customized invoice.
Dim strMessage As String
Dim dbsSuperdatabase As Database
Dim rstManufacturers As DAO.Recordset
strMessage = "This invoice has been customized. Do you want to print
the invoice from there?"
If YesNo(strMessage) Then
CustomLine1FOB.SetFocus
Exit Sub
End If
End If
End If

'Before previewing the invoice, update all the information.

'Post Total CIP to the shipments table.
'Shipments = Invoices Qry
Me![TotCIP] = Me![TotalCIP]

'Be sure the country field is filled in.
If IsNull(Destination) Then
'Dim strMessage As String
'Dim dbsSuperdatabase As Database
strMessage = "A destination country is required. Do you want to do that now?"
If YesNo(strMessage) Then
Destination.SetFocus
Exit Sub
End If
End If

'Post the invoice terms to the invoice
If IsNull(InvoiceTerms) Then
If Not IsNull(Sold_To) Then
If Not IsNull(CcTerms) Then
InvoiceTerms = CcTerms
Else
MsgBox "The invoice requires terms. First check that you have
the customer from the drop-down box. Then enter the customer default terms.
When you click on 'invoice' the terms will automatically populate."
ClientClientTerms.SetFocus
Exit Sub
End If
Else
If IsNull(CcTerms) Then
If Not IsNull(ClientTerms) Then
InvoiceTerms = ClientTerms
Else
MsgBox "The invoice requires terms. First check that you have
the customer from the drop-down box. Then enter the customer default terms.
When you click on 'invoice' the terms will automatically populate."
ClientTerms.SetFocus
Exit Sub
End If
End If
End If
End If

Me.REFRESH
'Verify that someone's name is on theinvoice.
If EmployeeID = 0 Then
MsgBox "Please enter the name of the person who will sign the invoice."
EmployeeID.SetFocus
Exit Sub
End If

If IsNull(EmployeeID) Then
MsgBox "Please enter the name of the person who will sign the invoice."
EmployeeID.SetFocus
Exit Sub
End If

'Verify that ship type has been specified.
If ShipType = 0 Then
strMessage = "A ship type is required. Do you want to do that now?"
If YesNo(strMessage) Then
ShipTypeOption.SetFocus
Exit Sub
End If
End If

'Verify that there is a sold to address:
If IsNull(SoldToAddress) Then
strMessage = "A SOLD TO address is required. Do you want to do that now?"
If YesNo(strMessage) Then
SoldToName.SetFocus
Exit Sub
End If
End If

'Verify that there is a shipto address.
If IsNull(ShipAddress) Then
If ShipCompany <> "TO BE DETERMINED" Then
strMessage = "A SHIP TO address is required. Do you want to do that now?"
If YesNo(strMessage) Then
ShipCompany.SetFocus
Exit Sub
Else
End If
End If
End If

'Make sure the record is saved before editing the invoice address
'put at beginning of procedure.
'If Me.Dirty Then Me.Dirty = False 'save any main form changes before moving
to the rfq subform

'Open the report. Filter sends it to either Invoice or InvoiceLava

Dim stDocName As String
stDocName = "Invoice"
' Print Invoice report, using Invoices Filter query to print
' invoice for current order.
DoCmd.OpenReport stDocName, acPreview, "qryInvoiceFilter"

Exit_InvoiceS_Click:
Exit Sub

Err_InvoiceS_Click:
MsgBox Err.Description
Resume Exit_InvoiceS_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