Solved

Why does my subform remain enabled after I disable it?

Posted on 2011-02-10
21
429 Views
Last Modified: 2013-11-28
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?
0
Comment
Question by:sib_user
  • 9
  • 6
  • 3
  • +2
21 Comments
 
LVL 75
ID: 34865103
s/b working:

Me.[HH_Subform].Enabled = False

mx
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34865121
make sure that you are using the subform name and not the name of the source object


me.[nameofsubform].enabled=false
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 34865134
Also, setting them to Locked = True might be a better approach.
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 40

Expert Comment

by:als315
ID: 34865181
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
 
LVL 75
ID: 34865221
"Form have no .Enabled property"
It's a Sub Form Control, which does have an Enabled property.

mx
0
 

Author Comment

by:sib_user
ID: 34865311
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
 
LVL 40

Expert Comment

by:als315
ID: 34865528
You are correct, there is difference between subform control and subform.
0
 

Author Comment

by:sib_user
ID: 34865565
Here is the app.

Click on the first button on the main menu to bring up the offending page.
VISITATION3.mdb
0
 
LVL 75
ID: 34865642
Need the VBA Password ....

mx
0
 

Author Comment

by:sib_user
ID: 34865657
Thought I took that off.  Its scouser.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34865661
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
 
LVL 75
ID: 34865748
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
 

Author Comment

by:sib_user
ID: 34865752
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
 
LVL 75
ID: 34865761
I also had to comment out code in On Load because of missing reference (in A2010) to calendar control.  

mx
0
 
LVL 75
ID: 34865814
"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
 

Author Comment

by:sib_user
ID: 34865884
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
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 total points
ID: 34865922
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
 
LVL 75
ID: 34865942
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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34866044


<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
 
LVL 75
ID: 34866121
In the version I downloaded @ http:#a34865565 ... CHECKED was already visible !  

mx
Capture1.gif
0
 

Author Closing Comment

by:sib_user
ID: 34866368
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

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question