Solved Code running report despite default set to not

maybe your db apps get Stoned:sick:
 
However, this thought just popped into my head. Go into that app, opened for development. Uncheck the VBA library.
The VBA library cannot be removed

Nor can the obj lib be removed.

UnremovableRefs.png
 
I manually examined the pub constants in all the modules, but did not find any declared as vbDefaultButton2.

ExaminedModules.png
 
What if you declare it separately as the correct value e.g.

Public Const vbDefaultButton2 = 256

Then compile, compact and repair, and check it's value again?
Then remove the declaration and see if the correct value sticks?
 
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)
 
What if you declare it separately as the correct value e.g.

Public Const vbDefaultButton2 = 256

Then compile, compact and repair, and check it's value again?
Then remove the declaration and see if the correct value sticks?

That worked! ... But is this the right way to solve the problem?

ForceValue.png
 
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.
 
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?
 
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