473,322 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Using the value of a boolean variable in two forms without automatic reset to false

10
I have a subform1 and it has a nested subform2. there is a button in subform1 which will set the value of a boolean variable (say the variable name is MyVar) to true. Thats the task for the button on subform1.

Now, in the before update event of the Source Object(which is a form) of subform2 I want to check the value of MyVar. If MyVar is true then set it to false and do something if not then do some other thing.

My objective is to check if the user has clicked the button on subform1 or not. And do the task ahead according to that.


Hope you have got it.
Access bosses please help me on this.
Dec 20 '17 #1

✓ answered by NeoPa

Let me see if I can outline some possibilities for you then :
  1. Global variables - preferably declared in standard modules.
    Different versions of Access (or maybe it's the Expression Service which * may * actually be in Jet or ACE.) allow, or don't allow, such variables to be referenced from within QueryDefs.
    It's possible to return such values via a Function interface if not accessible directly.
    If the project is reset using the End statement or by resetting from within the VBA IDE then this value is lost in spite of Access still continuing.
    Probably not ideal for you.
  2. TempVars.
    Introduced in ccess 2007 so not available for earlier versions.
    Not VBA variables but objects attached to the database session.
    Not possible to declare a type so are all Variants I believe.
    Last from being added to the TempVars Collection until the database is closed or they are removed from the Collection explicitly.
  3. Controls on a Form/Report that's Left Open.
    Requires a Form (or Report) object is left open throughout the session.
    Lost once the Form/Report object is closed.
    Typically used along with hiding the Form/Report object and capturing and canceling any attempts to close it except via your proscribed method.
  4. Database Properties.
    Probably the best solution available but accessing via the Expression Service may not work well.
    May need to create a Function interface to set and/or return the values.
    Can be typed (String, Boolean, Long etc.)
    Don't even get destroyed automatically when the database is closed.
I hope you find one or other of these ideas suitable for your needs.

7 3268
rawled
10
Well, I am doing a lot of trial and error on this. It worked once then again the same. The variable must keep the value unchanged set by the button. Problem is it always changes to false automatically no matter I set the value with the button or not.


Please reply someone.
Dec 20 '17 #2
PhilOfWalton
1,430 Expert 1GB
I think you are not getting any replies because I am not sure you are using the word Subform correctly.

A subform is a control on a form (possibly looking similar to a listbox) which happens to also be a form.

It is NOT a form opened by pressing a button on some sort of navigation or menu type form.

I apologise if I have misunderstood, but neither question makes sense to me as they stand.

Phil
Dec 20 '17 #3
Rabbit
12,516 Expert Mod 8TB
You're running into scope issues. Where is this variable? Where's your code? You haven't given us enough info to go on.

If this variable exists only in the function, then you can't access it from anywhere else. If you try to access it anywhere else, it creates a different variable with the same name with the default value.

If you want to access it from multiple locations, you need to store the variable in a global location. Either at the module level, or in a table, or the TempVars collection.

But this is just guessing because you haven't told us where this variable is and what your code looks like.
Dec 20 '17 #4
NeoPa
32,556 Expert Mod 16PB
It seems to me you've tried something in your project which isn't working as you'd like it to.

So, you ask what's wrong with what you've done, but at no point do you share what it is that you have done. Does that sound about right? If so then you need to stop and think what's wrong with the above and rectify the thread so that we have a single question that it's possible for us to help you with.
Dec 20 '17 #5
rawled
10
Thank you all for your replies.
It seems i couldn't state the situation properly. Sorry for that. Here is some more info:
I just want to know a way to declare a variable which will not be reset to default until i close the ms access program. It must hold its value assigned by any operation(i.e. by a code) and if i use that variable anywhere in my database it will give me that value.
I am giving a simple example:
Suppose, I have 2 forms- form1 & form2
For a control in form 1 i have the following code:
Code1: Private Sub Button1_Click()
Dim MyVar as Boolean
MyVar= True
End Sub

Now for another control on form2 the code is:
Code2: Private Sub Button2_Click()
If (MyVar=True) Then
MsgBox "Bingoo! Someone clicked button1 in form1 before clicking button2."
MyVar=False
Else
MsgBox "No one clicked on button1 in form1"
End Sub

If the value of MyVar is set to false automatically after executing code1 i will never get a true value for the if argument. I know that the above code will not work and I need a global variable. Hope you got it now.
Dec 21 '17 #6
NeoPa
32,556 Expert Mod 16PB
Let me see if I can outline some possibilities for you then :
  1. Global variables - preferably declared in standard modules.
    Different versions of Access (or maybe it's the Expression Service which * may * actually be in Jet or ACE.) allow, or don't allow, such variables to be referenced from within QueryDefs.
    It's possible to return such values via a Function interface if not accessible directly.
    If the project is reset using the End statement or by resetting from within the VBA IDE then this value is lost in spite of Access still continuing.
    Probably not ideal for you.
  2. TempVars.
    Introduced in ccess 2007 so not available for earlier versions.
    Not VBA variables but objects attached to the database session.
    Not possible to declare a type so are all Variants I believe.
    Last from being added to the TempVars Collection until the database is closed or they are removed from the Collection explicitly.
  3. Controls on a Form/Report that's Left Open.
    Requires a Form (or Report) object is left open throughout the session.
    Lost once the Form/Report object is closed.
    Typically used along with hiding the Form/Report object and capturing and canceling any attempts to close it except via your proscribed method.
  4. Database Properties.
    Probably the best solution available but accessing via the Expression Service may not work well.
    May need to create a Function interface to set and/or return the values.
    Can be typed (String, Boolean, Long etc.)
    Don't even get destroyed automatically when the database is closed.
I hope you find one or other of these ideas suitable for your needs.
Dec 22 '17 #7
rawled
10
Thank you all for your nice cooperation. This is a great community. Sorry that I have to choose one answer as the best. You all are great people.
Dec 22 '17 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: F. Da Costa | last post by:
Hi all, Following two sniperts of code I'm using and getting very interesting results from. ..html <tr id="1" class="segment" open="false"> This is the segment under 'investigation' ..js
50
by: Steve | last post by:
How do you rewrite the swap function without using a tmp variable in the swap function???? int main() { int x = 3; int y = 5; // Passing by reference
12
by: Mal Ice | last post by:
I am creating an initial index.htm page on which I show some disclaimers and introduction information. In the head section I have Javascript which determines the screen resolution of the client....
4
by: nirjhar.oberoi | last post by:
Hi, This is my first post on this group! i am beginner lever C programmer. I am trying to add two numbers or multiply them using a single variable! Your are not allowed to use Unions or any...
2
by: jobooker | last post by:
I'm having issues sorting. The short description is, how do I set the select attribute of xsl:sort to be the value of an xsl:variable? The longer description follows: What I want to do is to be...
2
by: Sapphire25 | last post by:
Hello, this is my first time posting here. I am teaching an introductory programming course, but I have one student who is very advanced and needs to be challenged. I am using VB 6.0, and what I...
1
by: shiniskumar | last post by:
how to check if the value of a boolean variable is true of false in ftl? ive got a boolean variable whose value is false i have to perform some action based on its value in front end how do i...
1
by: BrianDaze | last post by:
Hi, I am new to Reflection in C#, and hoping someone could give me pointers on how to set a variable using Reflection. The variable name, type, and value are stored in a sql server database...
7
by: Nilou | last post by:
Hi, I'm writing a form to get numbers in order to calculate the price. if numbers and the code of business is wrong it will give me message box error. The result will appear on a rich text box....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.