473,548 Members | 2,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Remember a Toggle Button's state

JustJim
407 Recognized Expert Contributor
Hi All
I have a little application I'm working on for the local Department of Education. There is a "Main Menu" form that has a toggle button on it to show/hide the Database Window. When it is clicked it does the following

Expand|Select|Wrap|Line Numbers
  1. Private Sub tglDBwindow_Click()
  2. DoCmd.SelectObject acTable, , True
  3.  
  4. If tglDBwindow Then
  5.     Me.SetFocus
  6.     'Me.tglDBwindow.DefaultValue = "True"
  7.     Me.OpenArgs = True
  8.     Else
  9.     DoCmd.RunCommand acCmdWindowHide
  10.     'Me.tglDBwindow.DefaultValue = "False"
  11.     Me.OpenArgs = False
  12. End If
  13.  
  14. End Sub
As you can see, I am trying to get the form to remember the state of the toggle button so that when users navigate away from the main menu form to another form and back again (all unused forms are closed by the opening of the next one (this could be a mistake but it is neat and tidy!))

Now although Access Help says that both DefaultValue and OpenArgs are read/write, when I run the above code (with either DefaultValue or OpenArgs remarked out) I get the following error msg.

Error 2135 The property is read only and cannot be set.

Am I going about this the right way? Is there a better way?
May 14 '07 #1
5 10091
JConsulting
603 Recognized Expert Contributor
Hi All
I have a little application I'm working on for the local Department of Education. There is a "Main Menu" form that has a toggle button on it to show/hide the Database Window. When it is clicked it does the following

Expand|Select|Wrap|Line Numbers
  1. Private Sub tglDBwindow_Click()
  2. DoCmd.SelectObject acTable, , True
  3.  
  4. If tglDBwindow Then
  5.     Me.SetFocus
  6.     'Me.tglDBwindow.DefaultValue = "True"
  7.     Me.OpenArgs = True
  8.     Else
  9.     DoCmd.RunCommand acCmdWindowHide
  10.     'Me.tglDBwindow.DefaultValue = "False"
  11.     Me.OpenArgs = False
  12. End If
  13.  
  14. End Sub
As you can see, I am trying to get the form to remember the state of the toggle button so that when users navigate away from the main menu form to another form and back again (all unused forms are closed by the opening of the next one (this could be a mistake but it is neat and tidy!))

Now although Access Help says that both DefaultValue and OpenArgs are read/write, when I run the above code (with either DefaultValue or OpenArgs remarked out) I get the following error msg.

Error 2135 The property is read only and cannot be set.

Am I going about this the right way? Is there a better way?

Couple of ways,

You could create a small one field table to hold the true false...set the toggle's control source to that field.

You could set a global variable to true or false, then read it when your form opens. Boolean fields (global or not) default to false.

J
May 14 '07 #2
missinglinq
3,532 Recognized Expert Specialist
From Access Help:

OpenArgs Property

This property is available only by using a macro or by using Visual Basic with the OpenForm method of the DoCmd object. This property setting is read-only in all views.
May 14 '07 #3
JustJim
407 Recognized Expert Contributor
Thanks Guys.

As usual, it's so easy and obvious once someone points it out.

Again, Thank you

Jim
May 14 '07 #4
NeoPa
32,564 Recognized Expert Moderator MVP
FYI Jim.

OpenArgs is set by the call to open the form. It is passed from the calling code and, as such, is read-only within the form that has been called.

However, as this is only accessible to the code in the called form if accessed as a first thing, it is generally used by immediately copying the value (Me.OpenArgs) into a separate, publicly available variable for any later references. Clearly, once this has been done, the public variable is not only available for reading, but can also be overwritten where required too. An example of when this might be required is when a date is passed but you need a date string in a particular format.

Hope this helps.
May 23 '08 #5
NeoPa
32,564 Recognized Expert Moderator MVP
I just thought I'd add a further bit of explanation more specific to the original question.
A fundamental difference between the two approaches (OpenArgs & a table) is that OpenArgs is session dependent, whereas tables keep the information until it's changed.

In real terms this means that if the information is only required within the current session then OpenArgs would be appropriate (although the table could be used for this in almost all situations), but if the information is required to persist across various current sessions, or even between separated sessions, then the table is required.

I hope this clarifies the issues a little.
May 23 '08 #6

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

Similar topics

0
2279
by: Aravind | last post by:
Hi folks. I have a form, frmHistory, which has 3 toggle buttons (1 of which is tglName, which I will be using to demonstrate my problem). The buttons are used to sort the form (explanations below). I have set the button's "Triple State" value to Yes, and the default value to False. Here is the macro that I used for tglName (I assigned the...
2
3345
by: John | last post by:
Hi How can I create a toggle button on a toolbar that would enable/disable editing on the current form? Thanks Regards
4
4337
by: Neil Coleclough | last post by:
I am constructing a database to process product returns for my Company. I have a number of toggle buttons to identify the stage to which each return has been processed. For example, clicking the first button confirms that the goods are now in our building awaiting initial processing. This button then fires off an email to our warehouse staff...
5
3431
by: Steven | last post by:
Can anyone tell me how to toggle the "Caps Lock" key? Thanks in advance
2
7953
by: Mel | last post by:
Hi, is there any way I can implement toolstrip toggle button simular to the MS Word alignment button? if one toggle button already pressed down, if user click on the "pushed down button", the other toggle button will push down and the "pushed down button" will push up. I have trying to find groupID for toolstrip button, but seem like they...
3
3813
by: Killer42 | last post by:
Hi all. I have a frame with some toggle buttons in it. All is working fine, except that the user can't tell which option is selected to begin with. How do I set one of the toggle buttons to the down position at design time? (All controls are unbound). I have done some searching on TheScripts, and found a couple of cases where it was...
2
2608
by: newfie912 | last post by:
I have an online application used for grading students. On one of the pages, I have a table with two rows and each row has 16 cells. The upper row contains the letter grade (A, A-, B+, B, etc) and the lower row has a 16 radio buttons for selecting the appropriate grade. This all writes to a SQL server back-end and has been working fine for...
1
4424
by: Jeffrey Christiansen | last post by:
I wanted to add a toggle button to a VB2005 form to be used for a simple Windows Application (i.e. compiled to a "*.exe"), so I added the ActiveX Microsoft Forms Object toggle button, however I can't get this button does work properly. The documentation I found in the FM20.CHM files says the button state can be determined from its "Value"...
6
4006
by: ethanhines | last post by:
I am trying to dynamically change the value of a filed using a toggle button in a form it is not a yes or no question. I want it to change a value in a table based on it"s state. Toggled on="6 inches" Toggled off=<null>. I want to more then one toggle button on the form each one dynamically changing the value of the table in real time. How do I do...
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7954
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7467
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7805
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6039
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5367
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5085
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1932
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1054
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.