Yes/no function on form to control sunform

Musicman76

New member
Local time
Today, 20:15
Joined
Dec 1, 2024
Messages
6
Hi All,
I apologise if this has been asked previously, but I can't seem to find the answer anywhere, and I have gone through hours of youtube Videos and through this forum.

I have a form with a subform, I would like to click on the yes/no button to make the form inactive and I would like to make the records in the subform inactive as well.

E.G. Parent form is details of a Patient, the subform has all the contacts relating to the patient. I would like all the contacts to become inactive when I make the patient inactive. Is that possible?

T.I.A.


Kayron
 
Yes.
You could set the Allows to False when the patient is inactive.
1733050696830.png

You could also set the subformcontrol enabled to False.

I probably would not have a Yes/no option, but some conditions that determine if the patient is active or not.
 
“I probably would not have a Yes/no option, but some conditions that determine if the patient is active”

Hi,
Such as?

I currently have a combo box with yes/no that feeds from a “yes/no” table, 1 = yes 2 = No and I have the form feed from a query with 1 in the criteria, so it displays the active patients. I actually need have the for the records in the Subform, it’s important to be able to make the “contacts” I.e the records on the subform also become inactive, I hope I’m explaining myself properly
 
So how do you get the Inactive patients into the form?
 
The process above is how I make the patients (on the parent form) active/inactive, the same method is used for their contacts (the contacts are saved in a separate table). So I have a table for the patients, with a yes/no (1 or 2 as above) this table is then in query with a criteria to display 1 (yes only). If I want to turn patient to inactive then I change the yes/no form the combo.
 
So test for that Yes/No control

You could have
Code:
Me.SubFormControl.Enabled = Me.blnActive

Adjust your names to suit.
 
E.G. Parent form is details of a Patient, the subform has all the contacts relating to the patient. I would like all the contacts to become inactive when I make the patient inactive. Is that possible?
What does "inactive" mean? If the parent record is "inactive", you don't need to duplicate that information for each subform record. Does "inactive" mean that you don't want these records returned by a search? If so, that requires changing every query that returns these records to take account of the value of the inactive flag. If you mean that you want to use the inactive flag to prevent updates to the parent and child records, then you would use code in the form and subform's on Dirty event and on Delete Confirm event to prevent actions to change/delete the records. If you want something visual rather than just the inactive flag itself, you should be able to use conditional formatting.
 
Just for thinking & discussion purposes, what is there about a combo box that makes you want to NOT use a check box? You can have a ckbox_Click event just like the cbobox_Click event. Both types of control have a .Value property. In fact, the combo's .Value to be used as you described it would require one slight extra step since you are using 1 and 2 as values, when a checkbox uses 0 and -1. You can easily issue an "IF chkbox THEN..." to decide whether something is active or not, but for the combo it is "IF cbobox = 2 THEN..." - admittedly a tiny difference, but it permeates through code. The fact that a checkbox value conforms to VBA's definitions of TRUE and FALSE is not a factor to be discarded lightly, mostly due to the lesser amount of typing and the greater amount of clarity.

The approach I would take is that for forms, when you load a record and the Form_Current event recognizes that something IS disabled, you can set the form and sub-form .AllowEdit (and the other .Allowxxxx properties) to FALSE before you exit that event's code. It wouldn't stop you from navigating, which would just trigger a _Current event on a different record.

If the chkbox is defined to be TRUE when the patient is ACTIVE and the control name is [PatientActive] and the control containing the subform is called sbfDetails, ...

Code:
Private Sub Form_Current
...
Me.AllowEdit = Me.PatientActive      'disallow changes for inactive patients
Me.sbfDetails.Form.AllowEdit = Me.PatientActive
...

Two lines of code and your forms are now blocked for editing. You add other lines as needed for the other .Allowxxxx properties, that's how simple this gets because the checkbox TRUE is the same as the VBA TRUE and the SQL TRUE when done this way. (Note that VBA's TRUE has a different name - vbTrue - but the VALUE is the same.)
 

Users who are viewing this thread

Back
Top Bottom