Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 21st, 2005, 06:50 AM
Registered User
 
Join Date: Jun 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with VBA Disable/Enable text boxes

Hi,
I'm a SQL programmer mainly, and have never really worked with VBA before. However, I have been tasked with building an access database. Basically, what I am trying to do is on one of the forms there are a set of questions to be answered ("Yes" and "No"). If certain questions are answered in a certain way I want to stop users from entering information into certain other questions. I've looked in a few books and have come up with this code (which I attach as an Event Procedure against AfterUpdate in the properties of the field)

Private Sub PaidEmploy_AfterUpdate()
If DataEntry!PaidEmploy = "Yes" Then
        DataEntry!WorkEx.Enabled = False
        DataEntry!WorkEx.Locked = True
    Else
        DataEntry!WorkEx.Enabled = True
        DataEntry!WorkEx.Locked = False
    End If
End Sub

However, when I run the form it gives me the following error in the debugger;
"Compile Error;
Qualifier must be collection"

Can anyone help me on this please, it would be most appreciated!!!

Thanks
:)

 
Old June 21st, 2005, 07:18 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Hi, your code is not too far off. It depends what exactly the control PaidEmploy is. Is it a checkbox or a textbox or a combobox?

Textbox or combobox:

If Me.PaidEmploy = "Yes" Then
    Me.WorkEx.Enabled = False
Else
    Me.WorkEx.Enabled = True
End If

or simply

Me.PaidEmpoy.Enabled = Not (Me.PaidEmploy = "Yes")

If it's a checkbox then

If Me.PaidEmploy Then
    Me.WorkEx.Enabled = False
Else
    Me.WorkEx.Enabled = True
End If

or simply

Me.WorkEx.Enabled = Not Me.PaidEmploy

The expression "Me." is a shortcut for "Forms!DataEntry.Form." assuming "DataEntry" is the name of your form.

There's no need to lock WorkEx. When you disable AND lock it, it doesn't appear "grayed out." That's a good indicator to the user that's it's disabled.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old June 21st, 2005, 07:27 AM
Registered User
 
Join Date: Jun 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thankyou Greg, the first suggestion worked like a charm!! Many Thanks!! =)

 
Old February 10th, 2007, 03:47 PM
Registered User
 
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am basically trying to do the same thing. Based on what is selected in an option group, text boxes will be enabled/disabled. For example... If DHCP is clicked then only IP Address is enabled, if Static is checked then Ip Address, Subnet Mask, and Default Gateway are enabled. Any help would be appreciated.

 
Old February 10th, 2007, 08:43 PM
Registered User
 
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK i got what i was trying to do to work... i should have done more research before i posted. But there is a bug that would make me needing this pointless... example:
When i click DHCP it changes all the records to DHCP... when i click Static it changes all records to static... AND if i open the form when DHCP is selected, it doesn't disable the boxes until i select Static then DHCP again... if anybody has fix for this it would be great. i hardly know anything about vba... all i know is what i want to do then altering sample code until i get it to work.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Using JS to enable/disable?? crabjoe Javascript 4 November 10th, 2008 06:48 PM
Enable Update and Enable Delete check boxes don't mihabib ASP.NET 2.0 Basics 2 December 7th, 2006 11:44 AM
Disable and Enable at runtime Hammam ASP.NET 1.0 and 1.1 Professional 0 May 17th, 2006 12:40 AM
Access VBA - Controlling Text boxes in a form Scripts82 Access VBA 4 February 8th, 2006 08:35 PM
Disable/Enable elements ldoodle Javascript How-To 3 June 7th, 2005 05:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.