473,498 Members | 1,785 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 10076
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,557 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,557 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
2274
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...
2
3339
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
4329
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...
5
3423
by: Steven | last post by:
Can anyone tell me how to toggle the "Caps Lock" key? Thanks in advance
2
7944
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...
3
3792
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...
2
2597
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)...
1
4414
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...
6
4001
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...
0
6993
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7162
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7375
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...
0
5456
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,...
1
4899
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...
0
4584
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...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1411
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 ...

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.