My Assistant
![]()
Custom Search
|
![]() ![]() |
![]() |
![]() Post#1 | |
Posts: 546 Joined: 26-May 11 ![]() | Hi All, I have a form where I have a procedure to lock and a procedure to unlock select controls. The lock get fired on form load, and each proc is controlled by a button. Here's an example of the lock code: CODE For Each ctl In Me.Controls If ctl.Tag Like "*lock*" Then ctl.Locked = True End If Next ctl boolFormIsLocked = True boolFormIsLocked is a Boolean that's declared in the general declarations area of the form. The purpose of it is that there are certain controls, even when the form itself might be unlocked, need to be locked if some other conditions are met. The problem is that when I come to use boolFormIsLocked to make that determination, I find that it's somehow flipped from the last time I set it. I cannot figure out why or where this is happening. Are there some things that happen in a form that can flip a boolean value without me directly addressing it in code? Thanks, Toby. -------------------- thanks, fizzy1. |
![]() Post#2 | |
![]() UA Moderator Posts: 76,820 Joined: 19-June 07 From: SunnySandyEggo ![]() | I doubt it. Try searching your entire project for the name of the variable. Perhaps there's a name conflict, somehow/somewhere, where you're getting a value from another variable (global) rather than the one you're expecting (i.e. the local one). Just a thought... -------------------- Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas Access Website | Access Blog | Email |
![]() Post#3 | |
![]() UtterAccess VIP Posts: 11,250 Joined: 10-February 04 From: South Charleston, WV ![]() | Does it always "flip" to False? I suspect you're reopening the code and it's getting initialized. -------------------- Robert Crouser |
![]() Post#4 | |
Posts: 546 Joined: 26-May 11 ![]() | This variable is only present in this form. In the "lock" button I set the bool = true then on the OnEnter event of a control in my datasheet I have it echo back the value of the bool. I lock the form then immediately click into the control and the value has changed! This is really confusing me. Lock code: CODE Private Sub cmdLockMode_Click() LockForm ' boolean gets set here Me.cmdEditMode.Enabled = True Me.cmdLockMode.Enabled = False RunCostRollUp boolFormIsLocked = True ' for means of testing I'm setting it True again here Then I immediately click into this control: CODE Private Sub txtApprovedVendorCost_Enter() Debug.Print "txtApprovedVendorCost_Enter: boolFormIsLocked = " & boolFormIsLocked and it comes back as False, when the last thing that happened was for it to be set True. -------------------- thanks, fizzy1. |
![]() Post#5 | |
![]() UtterAccess VIP Posts: 11,250 Joined: 10-February 04 From: South Charleston, WV ![]() | So you have Dim boolFormIsLocked As Boolean in your code, right? Change that to Static boolFormIsLocked As Boolean and try it. -------------------- Robert Crouser |
![]() Post#6 | |
![]() UtterAccess VIP Posts: 1,879 Joined: 4-June 18 From: Somerset, UK ![]() | Robert Just wondering why would you expect changing Dim to Static to make any difference? -------------------- |
![]() Post#7 | |
Posts: 546 Joined: 26-May 11 ![]() | I have it in the general declarations area of the header of form's module, like this: CODE Option Compare Database Option Explicit Dim boolFormIsLocked As Boolean If I replace the "Dim" with "Static" it errors saying I can't do that as it's invalid outside of a procedure. -------------------- thanks, fizzy1. |
![]() Post#8 | |
![]() UtterAccess VIP Posts: 11,250 Joined: 10-February 04 From: South Charleston, WV ![]() | That would be to prevent it from being reinitialized upon entry into a procedure. If it's at the top of the form's code, it would not be reinitalized unless the form were reopened. So you can forget about that. -------------------- Robert Crouser |
![]() Post#9 | |
Posts: 546 Joined: 26-May 11 ![]() | Hmm, so what could the issue be? It literally from one command to the next flips / resets. -------------------- thanks, fizzy1. |
![]() Post#10 | |
![]() UtterAccess VIP Posts: 11,250 Joined: 10-February 04 From: South Charleston, WV ![]() | Did you put a stop on boolFormIsLocked = False? If there is no boolFormIsLocked = False, you could rename the variable and see what happens. -------------------- Robert Crouser |
![]() Post#11 | |
![]() UtterAccess Moderator Posts: 11,870 Joined: 6-December 03 From: Telegraph Hill ![]() | An unhandled error in your application will reset it to false. -------------------- Regards, David Marten |
![]() Post#12 | |
![]() UA Admin Posts: 36,171 Joined: 20-June 02 From: Newcastle, WA ![]() | When we only see chunks of code from different places, taken out of context, it can be harder to guess what might be happening in other places not shown, so maybe we could do a better job of offering suggestions if we can see the full accdb. Can you provide a sample that illustrates this problem, with just enough sample data to test with? Compact and Repair the sample accdb and compress it into a ZIP file to be uploaded. Thanks. This post has been edited by GroverParkGeorge: Nov 15 2019, 10:05 AM -------------------- My Real Name Is George. Grover Park Consulting is where I did business for 20 years. How to Ask a Good Question Beginning SQL Server |
![]() Post#13 | |
Posts: 546 Joined: 26-May 11 ![]() | QUOTE Did you put a stop on boolFormIsLocked = False? If there is no boolFormIsLocked = False, you could rename the variable and see what happens. Sorry, not quite sure what you mean by "stop". I do, though, have elsewhere a command that sets boolFormIsLocked = False, but that should not get fired between me setting it True and then the problem occurring. QUOTE An unhandled error in your application will reset it to false. Hmm, I do have some procs that don't have handlers. Let me drop them in there and see what happens. QUOTE When we only see chunks of code from different places, taken out of context, it can be harder to guess what might be happening in other places not shown, so maybe we could do a better job of offering suggestions if we can see the full accdb. Can you provide a sample that illustrates this problem, with just enough sample data to test with? Compact and Repair the sample accdb and compress it into a ZIP file to be uploaded. Working on a re-pro dbase now. I can't post the original. However, I just now tried using GotFocus instead of using OnEnter and it works as it should. The boolean echos back its correct state. What the heck? Doesn't OnEnter fire before GotFocus? -------------------- thanks, fizzy1. |
![]() Post#14 | |
![]() UtterAccess VIP Posts: 11,250 Joined: 10-February 04 From: South Charleston, WV ![]() | A stop is a break-point for debugging in the code. It is part of the debugging feature. If you put a stop on boolFormIsLocked = False you will know if that statement has been executed. Provided, of course, that statement exists. -------------------- Robert Crouser |
![]() Post#15 | |
![]() UA Admin Posts: 36,171 Joined: 20-June 02 From: Newcastle, WA ![]() | -------------------- My Real Name Is George. Grover Park Consulting is where I did business for 20 years. How to Ask a Good Question Beginning SQL Server |
![]() Post#16 | |
Posts: 546 Joined: 26-May 11 ![]() | There were no unhandled errors, so that's out, luckily. I've attached a repro dbase. Open it, watch the immediate window, and open Form1. The form sets the boolean on open, and then the Lock and Unlock buttons will also toggle its value. As you click around in the text controls in the datasheet you can see the boolean's value flip between the OnEnter and GotFocus events. Weird! ![]() -------------------- thanks, fizzy1. |
![]() Post#17 | |
![]() UA Admin Posts: 36,171 Joined: 20-June 02 From: Newcastle, WA ![]() | The value of this variable is lost when the sub executing your code ends. That means it reverts to the default "False". To make it a STATIC variable that will retain its value until your lock and unlock buttons change it, create a new, standalone module and place this line in it. CODE Option Compare Database Option Explicit Public boolFormIsLocked As Boolean Save it as modBoolLock or something similar. This post has been edited by GroverParkGeorge: Nov 15 2019, 11:58 AM -------------------- My Real Name Is George. Grover Park Consulting is where I did business for 20 years. How to Ask a Good Question Beginning SQL Server |
![]() Post#18 | |
![]() UA Admin Posts: 36,171 Joined: 20-June 02 From: Newcastle, WA ![]() | It occurs to me that maybe a bit more background on the lifetime of variables might be helpful. Placing this line in a form module only tells Access, "Here's the name of a variable you can use from time to time. No need to specify that name over and over." Dim boolFormIsLocked As Boolean That means the lifetime of the variable is the duration of an event fired within that form. Placing this line in a separate module tells Access, "Here's the name of a variable you can use from time to time. No need to specify that name over and over. Also, once you give that variable a value, it'll stay that way until another event changes it later on" Public boolFormIsLocked As Boolean That means the lifetime of the variable is the duration of the current Access session in which this variable is initialized by opening the accdb. -------------------- My Real Name Is George. Grover Park Consulting is where I did business for 20 years. How to Ask a Good Question Beginning SQL Server |
![]() Post#19 | |
![]() UtterAccess VIP Posts: 11,250 Joined: 10-February 04 From: South Charleston, WV ![]() | And there's no "flip". It always "flips" to false. If it was false before it "flipped" it would still be false after it "flipped". -------------------- Robert Crouser |
![]() Post#20 | |
Posts: 546 Joined: 26-May 11 ![]() | QUOTE And there's no "flip". It always flips to false. If it was false before it "flipped" it would still be false after it flipped. Right, I should have been more clear with my language. If it was True then it goes False, if it was False it stays that value. When I started this thread it looked like it was simply flipping; now after testing it more I see it's just going False. This post has been edited by fizzy1: Nov 15 2019, 12:22 PM -------------------- thanks, fizzy1. |
![]()
Custom Search
|
![]() | Search Top Lo-Fi | 7th December 2019 - 06:10 AM |