Code running report despite default set to not (5 Viewers)

Are these other projects on the same machine?
Yes
You COULD have a situation where an app does something that no other app does.
That's the case with this app. I did the Application.SaveAsText that Tom suggested and did not see any corruption. I also examined that forms code with a hex editor, but that was useless. So instead of beating this dead horse I did not use the vbDefaultButton2 constant, inverted my logic to the default Yes button, "DON'T print customer receipt?", and that works ugh.

Maybe some gremlin changed the vbNo constant to vbYes 👹

Code:
Private Sub cmdPrintReceipt_Click()
Dim response as String
response = MsgBox("DON'T Print Customer Receipt?", vbYesNo)
If response = vbYes Then Exit Sub
DoCmd.OpenReport "rptPrintCustomerReceipt", , , "[ContractNo] = " & Me.ContractNo
End Sub
 
Last edited:
Yes

That's the case with this app. I did the Application.SaveAsText that Tom suggested and did not see any corruption. I also examined that forms code with a hex editor, but that was useless. So instead of beating this dead horse I did not use the vbDefaultButton2 constant, inverted my logic to the default Yes button, "DON'T print customer receipt?", and that works ugh.

Maybe some gremlin changed the vbNo constant to vbYes 👹

Code:
Private Sub cmdPrintReceipt_Click()
Dim response as String
response = MsgBox("DON'T Print Customer Receipt?", vbYesNo)
If response = vbYes Then Exit Sub
DoCmd.OpenReport "rptPrintCustomerReceipt", , , "[ContractNo] = " & Me.ContractNo
End Sub
This worked for me:
Code:
Dim Response As Variant
Response = MsgBox("Run Report", vbYesNo + vbQuestion + vbDefaultButton2)
If Response = 7 Then Exit Sub
MsgBox "Run Report"
Exit Sub
The default is No so if you hit Enter, No (7) is selected and then Exit Sub, otherwise the message box shows "Run Report" and continues to Exit Sub.
I don't use single line If-Then statements but since you did, I did too. Can you run this routine OK?
 
The default is No so if you hit Enter, No (7) is selected and then Exit Sub, otherwise the message box shows "Run Report" and continues to Exit Sub.
I don't use single line If-Then statements but since you did, I did too. Can you run this routine OK?

I tried your code. Anything that involves the use of vbDefaultButton2 does not work for me in this particular app. I find that very strange, so I'm sticking with my default Yes "DON'T Print Receipt" code.
 
I have found that an Access VBA function name or other reserved word might have been defined elsewhere in the code but it doesn't seem plausible with vbDefaultButton2.
 
I tried your code. Anything that involves the use of vbDefaultButton2 does not work for me in this particular app. I find that very strange, so I'm sticking with my default Yes "DON'T Print Receipt" code.
vbDefaultButton2 also has a numerical value of 256. Try that instead and see if that works. I have never heard of this kind of error happening, so I am curious.
 
The only way I can replicate the OP's issue is if the Public constant vbYes is assigned to 7 somewhere in the code
Code:
Const vbYes = 7  ' Text to search.
 
Last edited:
I have found that an Access VBA function name or other reserved word might have been defined elsewhere in the code but it doesn't seem plausible with vbDefaultButton2.
vbDefaultButton2 also has a numerical value of 256. Try that instead and see if that works. I have never heard of this kind of error happening, so I am curious.
Wouldn't Access automatically flag a variable name starting with vb? Using 256 works, so something's up with using vbDefaultButton2.
 
Wouldn't Access automatically flag a variable name starting with vb? Using 256 works, so something's up with using vbDefaultButton2.
Try checking the definition of vbDefaultButton2 in the context of your database. You can right-click on vbDefaultButton2 from your MsgBox call then click Definition. It should bring you to to the definition where it will indicate the value of 256. If vbDefaultButton2 is defined locally somewhere in your codebase, it will bring you there. This should make it clear how that constant is defined in your database and if it is overridden somewhere.



Snip1.png
Snip2.png
.
 

Users who are viewing this thread

Back
Top Bottom