Code running report despite default set to not

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
.
 
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.



View attachment 122293View attachment 122294.
Who knows what ACCESS is doing behind the curtain. Here's a link to the Msgbox function in case you need it again:

This is so weird. it says vbDefaultButton2 has a value of 6, which is vbYes. No wonder it's printing despite pressing the No button. Something is definitely sticky corrupt in this db :rolleyes:

vbDefaultButton2.png
 
Last edited:
Yes, that is messed up. Wow.
Do you have any funny references that could interfere? Or have references in a non-standard order? The default 4 should always be first and in that same order.

EDIT: It is also suspicious that the hex value does not display. This is my A2010, with Northwind1 loaded:
1763326600829.png

These are the 4 references, plus a custom one.
1763326696798.png
 
Last edited:
Yes, that is messed up. Wow.
Do you have any funny references that could interfere? Or have references in a non-standard order? The default 4 should always be first and in that same order.

EDIT: It is also suspicious that the hex value does not display. This is my A2010, with Northwind1 loaded:
View attachment 122297
These are the 4 references, plus a custom one.
View attachment 122298

Does the hex value for vbYes display on your 2010?

This is what I posted in #39:
Maybe this db got stoned since it's for a chain of Marijuana Shops 😵‍💫

Ref.PNG
 
Last edited:
Seeing that the definition of vbDefaultButton2 is wrong means you have a conflicting definition. When you go to the Project Explorer in the VBA screen, you should be able to search for where it is defined. If I recall that feature correctly, you will get a list of places where the definition appears, specifically from the library files. But then you can ALSO do a search of the project to see where vbDefaultButton2 appears - and the question is whether it ever appears to the left of an equals sign in a LET statement (or equivalent). There is also the question of whether it ever appears as an argument in a function / sub where it is used ByRef AND that argument is read/write.

This would SURELY explain the bizarre behavior but still doesn't explain how this erroneous definition came about.
 
DefaultButton2 is wrong means you have a conflicting definition
I searched entire project and it only shows up in that On Click event. I thought it being a vba reserved word with a fixed constant that you cannot define a variable with that same name and assign it a different value?
 
When I defined a public const vbDefaultButton2 as integer = 6, in the object browser it appeared without its hex value.
I gotta believe the constant is defined more than once.
Also as evidenced by the absence of the problem in a new empty database.
I hope you have good tools to do a deep search.
 
When I defined a public const vbDefaultButton2 as integer = 6, in the object browser it appeared without its hex value.
I gotta believe the constant is defined more than once.
Also as evidenced by the absence of the problem in a new empty database.
I hope you have good tools to do a deep search.

I searched entire project and it only shows up in that On Click event., unless it's well hidden somewhere else? I don't recall defining it as a pub constant anywhere else. Then again, I inherited this app from the previous developer. Why would anyone do such a thing? I thought it being a vba reserved word with a fixed constant that you cannot define a variable with that same name and assign it a different value?
 
> I thought it being a vba reserved word with a fixed constant that you cannot define a variable with that same name and assign it a different value?
We have to use precise language. I did not define a variable, but a constant.
That constant is in a different library (app_name) than the official one (VBA).
Just like the Recordset object is in two libraries (DAO, ADODB).

If the code is not explicitly stating the library, then which one wins probably depends on some complicated logic. I would not count on that.

Of course we understand you did not define such constant on purpose. Yet we see the value with our own eyes. SOMETHING fishy must be up.
 

Users who are viewing this thread

Back
Top Bottom