Disable checkbox based on other values

I have a relatively simple continuous form. There is an invisible flag, let him call Frank.

There is a second flag (Ralph), which can be True or False. There is also a date text box (RalphDate).

If Frank is right, I don't want the user to be able to modify Ralph or RalphDate, regardless of what already exists.

Now RalphDate is simple in that I just use the conditional format to check the Frank value, which either turns on or off RalphDate. This flag is not available for the flag.

I'm stuck right now, because with some Visual Basic it sets the state of all Ralph boxes the same way based on the value of the first Frank value that it encounters. So the question is, how do I disable only the associated Ralph check flag based on the Frank flag, True?

+4
source share
4 answers

Solution 1

  • Update the Locked property instead of Enabled for ckRalph.
  • do this in the OnCurrent () event handler for the form.

The Locked property will prevent changes without a visual hint. This should take care of the functional part, even if visually the checkbox is still enabled, it cannot be changed.

Decision 2

Another way is to simulate this flag:

  • use a text box, name it fakeckRalph; make it a small square.
  • make your record source property something like ' =getstate() '
  • create a getstate function that does something like:

     Public Function GetState() as string GetState = iif(ckRalph, "V", " ") End Function 

I suggest using a character font and a character to make the checkmark better in your field.
So, if your Ralph is right, the checkbox will display a checkmark, and if not, it will be empty.

To complete the trick, use conditional formatting in the text box to disable it when Franck is right.
To make the click more realistic, also change the cursor to the hand pointer.

The last thing you need is to bind the OnClick event to our fakeckRalph text box fakeckRalph that we can switch the state of Ralph and display it correctly:

 Private Sub OnClick() Ralph = Not Ralph fakeckRalph.Requery End Sub 

I have similar methods for the user to show whether the recording in the continuous form has been locked (using the blue padlock symbol from one of the winding fonts) or can be deleted with a large red cross that can be clicked on:

image 2 http://img9.imageshack.us/img9/6296/sshot2do5.png image 1 http://img8.imageshack.us/img8/4997/sshot1ya5.png

+4
source

This is one of the shortcomings of continuous forms, and there is no way around it.

In general, I avoid editable continuous forms — I use them only to display the list and use the editable subform associated with the PK continuous form to display the current data for editing.

This avoids all the problems with the conditional display of certain controls, since you simply display data in a continuous form and can precisely control what is visible / included in the subform.

+1
source

Short answer: you cannot do this if you use continuous forms. Changing a control's setting changes it for all rows.

0
source

Set the Ralph control source for the function, for example =GetCheckState() . Then create a function like this:

 Public Function GetCheckState() as boolean If Frank then GetCheckState = True Else GetCheckState = False End If End Function 

This will control whether Ralph is checked or not based on Frank. Since the checkbox is bound to a function, it will not allow you to change the value by clicking it.

To respond to the user by clicking the field, add the code to the On Mouse Up event:

 Private Sub Ralph_MouseUp(Button As Integer, Shift As Integer, _ X As Single, Y As Single) If Button = acLeftButton And Not Frank Then Frank = True End If Ralph.Requery End Sub 

The Click event seems completely ignored when the function is the source of control, so you should use On Mouse Up (On Mouse Down works if you prefer this). You can also add similar code to the KeyDown event if you want the window to check when users press the spacebar or enter a key.

The only disadvantages are:

  • The box is not grayed out if it cannot be clicked.
  • Access will display a message in the status bar saying that the control cannot be edited due to the expression to which it attached when it pressed.

In the first case, you can display a message explaining this if you think that people will be embarrassed. Secondly, there is probably a way around it, but I could not find it. The message still appears even when I tried to set up my own status message in both the Mouse and Mouse events.

If you have a window with a gray color when it is turned off, this is very important for you, then this will not work, but I was dissatisfied with the appearance of the "simulated" flag that was proposed in the accepted answer. This method allowed me to control the functionality of the flag based on other entries and still use the actual flag.

0
source

All Articles