Why does my subform remain enabled after I disable it?

I have a main form (FORM_ED) and a sub form (HH_subform).
I want to disable certain command buttons on the main form
and the entire sub form depending upon the value of the field
CHECKED that is on the main form.  SO I put the following code
in the main form's current event handler:

Private Sub Form_Current()
If Me.CHECKED = True Then
    Me.[DIFFERENT_BUILDING_NEW_BUSINESS].Enabled = False
    Me.[DIFFERENT_BUILDING_NEW_HOUSEHOLD].Enabled = False
    Me.[DIFFERENT_BUILDING_NEW_VACANT_BUILDING].Enabled = False
    Me.[DIFFERENT_BUILDING_NEW_VACANT_DWELLING].Enabled = False
    Me.[SAME_BUILDING_NEW_BUSINESS].Enabled = False
    Me.[SAME_BUILDING_NEW_DWELLING_AND_HOUSEHOLD].Enabled = False
    Me.[SAME_BUILDING_SAME_DWELLING_NEW_HOUSEHOLD].Enabled = False
    Me.[SAME_BUILDING_NEW_VACANT_DWELLING].Enabled = False
    Me.[SAME_BUILDING_NEW_VACANT_HOUSEHOLD].Enabled = False
    [HH_Subform].Enabled = False
Else
    Me.[DIFFERENT_BUILDING_NEW_BUSINESS].Enabled = True
    Me.[DIFFERENT_BUILDING_NEW_HOUSEHOLD].Enabled = True
    Me.[DIFFERENT_BUILDING_NEW_VACANT_BUILDING].Enabled = True
    Me.[DIFFERENT_BUILDING_NEW_VACANT_DWELLING].Enabled = True
    Me.[SAME_BUILDING_NEW_BUSINESS].Enabled = True
    Me.[SAME_BUILDING_NEW_DWELLING_AND_HOUSEHOLD].Enabled = True
    Me.[SAME_BUILDING_SAME_DWELLING_NEW_HOUSEHOLD].Enabled = True
    Me.[SAME_BUILDING_NEW_VACANT_DWELLING].Enabled = True
    Me.[SAME_BUILDING_NEW_VACANT_HOUSEHOLD].Enabled = True
    [HH_Subform].Enabled = True
End If
End Sub

The problem, however, is that whereas all of the command
buttons are disabled when the value of CHECKED is TRUE,
the subform remains enabled or at least I can still enter data
into it.  How do I prevent the user from being able to enter data
into the subform when the value of CHECKED is true?
sib_userAsked:
Who is Participating?
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
OK ... I'm on my A2003 system now.  The *only* change necessary to make this work ... form your original is shown below:

Private Sub Form_Current()
If Me.CHECKED = True Then
    Me.[DIFFERENT_BUILDING_NEW_BUSINESS].Enabled = False
    Me.[DIFFERENT_BUILDING_NEW_HOUSEHOLD].Enabled = False
    Me.[DIFFERENT_BUILDING_NEW_VACANT_BUILDING].Enabled = False
    Me.[DIFFERENT_BUILDING_NEW_VACANT_DWELLING].Enabled = False
    Me.[SAME_BUILDING_NEW_BUSINESS].Enabled = False
    Me.[SAME_BUILDING_NEW_DWELLING_AND_HOUSEHOLD].Enabled = False
    Me.[SAME_BUILDING_SAME_DWELLING_NEW_HOUSEHOLD].Enabled = False
    Me.[SAME_BUILDING_NEW_VACANT_DWELLING].Enabled = False
  ' Me.[SAME_BUILDING_NEW_VACANT_HOUSEHOLD].Enabled = False  ' does not exist
    Me.HH_Subform.Enabled = False
Else
    Me.[DIFFERENT_BUILDING_NEW_BUSINESS].Enabled = True
    Me.[DIFFERENT_BUILDING_NEW_HOUSEHOLD].Enabled = True
    Me.[DIFFERENT_BUILDING_NEW_VACANT_BUILDING].Enabled = True
    Me.[DIFFERENT_BUILDING_NEW_VACANT_DWELLING].Enabled = True
    Me.[SAME_BUILDING_NEW_BUSINESS].Enabled = True
    Me.[SAME_BUILDING_NEW_DWELLING_AND_HOUSEHOLD].Enabled = True
    Me.[SAME_BUILDING_SAME_DWELLING_NEW_HOUSEHOLD].Enabled = True
    Me.[SAME_BUILDING_NEW_VACANT_DWELLING].Enabled = True
  ' Me.[SAME_BUILDING_NEW_VACANT_HOUSEHOLD].Enabled = True  ' does not exist
    Me.HH_Subform.Enabled = True
End If
End Sub
VISITATION3-MX01.zip
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
s/b working:

Me.[HH_Subform].Enabled = False

mx
0
 
Rey Obrero (Capricorn1)Commented:
make sure that you are using the subform name and not the name of the source object


me.[nameofsubform].enabled=false
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Helen FeddemaCommented:
Also, setting them to Locked = True might be a better approach.
0
 
als315Commented:
Form have no .Enabled property
You can make it unvisible with
.visible = false
or disable all edits etc. with:
.AllowAdditions = False
.AllowDeletions = False
.AllowEdits = False
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"Form have no .Enabled property"
It's a Sub Form Control, which does have an Enabled property.

mx
0
 
sib_userAuthor Commented:
mx, capricorn1, Helen_Feddema,
I've tried all of your suggestions and am still able to enter data into the subform.  

als315,
The subform does have an enabled property and in fact doesn't have any of those properties you mentioned.

I will post the app shortly and perhaps somebody may be able to make some sense of why the subform
remain enabled.
0
 
als315Commented:
You are correct, there is difference between subform control and subform.
0
 
sib_userAuthor Commented:
Here is the app.

Click on the first button on the main menu to bring up the offending page.
VISITATION3.mdb
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Need the VBA Password ....

mx
0
 
sib_userAuthor Commented:
Thought I took that off.  Its scouser.
0
 
Rey Obrero (Capricorn1)Commented:
i commented some codes in the load event of the form and make the check box visible so you can see, this is working
VISITATION3.mdb
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
The Line of code I commented out has a problem. When commented out, it's working fine - subform is disabled.

Private Sub Form_Current()
If Me.CHECKED = True Then
    Me.[DIFFERENT_BUILDING_NEW_BUSINESS].Enabled = False
    Me.[DIFFERENT_BUILDING_NEW_HOUSEHOLD].Enabled = False
    Me.[DIFFERENT_BUILDING_NEW_VACANT_BUILDING].Enabled = False
    Me.[DIFFERENT_BUILDING_NEW_VACANT_DWELLING].Enabled = False
    Me.[SAME_BUILDING_NEW_BUSINESS].Enabled = False
    Me.[SAME_BUILDING_NEW_DWELLING_AND_HOUSEHOLD].Enabled = False
    Me.[SAME_BUILDING_SAME_DWELLING_NEW_HOUSEHOLD].Enabled = False
    Me.[SAME_BUILDING_NEW_VACANT_DWELLING].Enabled = False
   '' Me.[SAME_BUILDING_NEW_VACANT_HOUSEHOLD].Enabled = False ' *****
    Me.HH_Subform.Enabled = False
Else
    Me.[DIFFERENT_BUILDING_NEW_BUSINESS].Enabled = True
    Me.[DIFFERENT_BUILDING_NEW_HOUSEHOLD].Enabled = True
    Me.[DIFFERENT_BUILDING_NEW_VACANT_BUILDING].Enabled = True
    Me.[DIFFERENT_BUILDING_NEW_VACANT_DWELLING].Enabled = True
    Me.[SAME_BUILDING_NEW_BUSINESS].Enabled = True
    Me.[SAME_BUILDING_NEW_DWELLING_AND_HOUSEHOLD].Enabled = True
    Me.[SAME_BUILDING_SAME_DWELLING_NEW_HOUSEHOLD].Enabled = True
    Me.[SAME_BUILDING_NEW_VACANT_DWELLING].Enabled = True
    Me.[SAME_BUILDING_NEW_VACANT_HOUSEHOLD].Enabled = True
    Me.HH_Subform.Enabled = True
End If
End Sub
0
 
sib_userAuthor Commented:
capricorn1,

I saw what you did but don't understand why it has the effect that it does.  Why does the visibility of the CHECKED control affect whether the subform is disabled or otherwise?
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
I also had to comment out code in On Load because of missing reference (in A2010) to calendar control.  

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"Thought I took that off."
Odd ... because VBA editor opens fine, but if I go to Tools>>References (again in A2010) ... then it asks for the password!  weird.

"Why does the visibility of the CHECKED control affect whether the subform is disabled or otherwise?"
I got it working simply by commenting out the On Load code (with Environ) because of the reference issue ... and the other line in the Current event that was causing an error. No other changes.

mx
0
 
sib_userAuthor Commented:
Mx,
I understand why your solution works.  I had deleted the command button SAME_BUILDING_NEW_VACANT_HOUSEHOLD and failed to delete all references to it.  

Rather strange behavior on the part of MS Access to simple stop executing without giving some feedback.  

Maybe this warrant some more points, but is it possible to get Access to complain about these bad references?
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Note ... no Reference issues on my A2003 system, so I did not need to comment out the On Load code ... just those two lines above.  

This control  SAME_BUILDING_NEW_VACANT_HOUSEHOLD  does not exist ... but some similar names do.

mx
0
 
Rey Obrero (Capricorn1)Commented:


<I saw what you did but don't understand why it has the effect that it does.  Why does the visibility of the CHECKED control affect whether the subform is disabled or otherwise?>

i t does not have any effect. as i've stated above
so you can see the condition or state of the check box
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
In the version I downloaded @ http:#a34865565 ... CHECKED was already visible !  

mx
Capture1.gif
0
 
sib_userAuthor Commented:
Thanks for all of your comments. As usual when I ask a question on MS Access of EE the responses are prompt and helpful.

Thanks again!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.