By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Remember a Toggle Button's state

JustJim
Expert 100+
P: 407
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
Share this Question
Share on Google+
5 Replies


JConsulting
Expert 100+
P: 603
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
Expert 2.5K+
P: 3,532
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
Expert 100+
P: 407
Thanks Guys.

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

Again, Thank you

Jim
May 14 '07 #4

NeoPa
Expert Mod 15k+
P: 31,347
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
Expert Mod 15k+
P: 31,347
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

Post your reply

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