Solved

Why does my subform remain enabled after I disable it?

Posted on 2011-02-10
21
421 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 119

Expert Comment

by:Rey Obrero
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
 
LVL 39

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 39

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 119

Expert Comment

by:Rey Obrero
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 - Access MVP) 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 119

Expert Comment

by:Rey Obrero
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now