Solved Code running report despite default set to not

  • Thread starter Thread starter Deleted Bruce 182381
  • Start date Start date
BlueSpruce,
Out of curiosity, only for testing, have you tried to delete all the database objects the except the form with the button with that issue? or Import only this form in a new database? (I know you've said if you import all the objects in a new database the behaviour is the same)
 
Yes, I tried. That was one of the earliest tests suggested to me. I only imported the form to a new accdb and the problem persisted. So something in that form must be corrupted.
Can you upload this database with only this form or part of it to see the issue?
 
That worked! ... But is this the right way to solve the problem?

View attachment 122307

Probably not, but it sort of forces the hand of the database. I've used the same method when Access decides it want to capitalise keywords incorrectly.
I'm not entirely sure why it works but I assume it "resets" some internal record/value somewhere.
 
As noted earlier, "String" is the wrong type for response, MsgBox returns a long, though your original code runs on my computer.
Have you tried calling out the enum with the value so you don't need to define the constant. This may not compile if something is wrong with those enum definitions.

Code:
Public Sub cmdPrintReceipt_Click()
Dim response As VbMsgBoxStyle
response = MsgBox("DON'T Print Customer Receipt?", VbMsgBoxStyle.vbYesNo)
If response = VbMsgBoxResult.vbYes Then Exit Sub
DoCmd.OpenReport "rptPrintCustomerReceipt", , , "[ContractNo] = " & Me.ContractNo
End Sub

Then with a default and changing the message to a positive.

VbMsgBoxStyle.vbYesNo + VbMsgBoxStyle.vbDefaultButton2

Code:
Public Sub cmdPrintReceipt_Click2()
Dim response As VbMsgBoxStyle
response = MsgBox("Print Customer Receipt?", VbMsgBoxStyle.vbYesNo + VbMsgBoxStyle.vbDefaultButton2)
If response = VbMsgBoxResult.vbNo Then Exit Sub
DoCmd.OpenReport "rptPrintCustomerReceipt", , , "[ContractNo] = " & Me.ContractNo
End Sub

Of course you could simplify by removing response and the short circuit.

Code:
Public Sub cmdPrintReceipt_Click3()
If MsgBox("Print Customer Receipt?", _
           VbMsgBoxStyle.vbYesNo _
         + VbMsgBoxStyle.vbDefaultButton2) _
  = VbMsgBoxResult.vbYes Then
    DoCmd.OpenReport "rptPrintCustomerReceipt", , , "[ContractNo] = " & Me.ContractNo
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom