Solved

Why does my subform remain enabled after I disable it?

Posted on 2011-02-10
21
431 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-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

733 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