Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable a field in a form 1

Status
Not open for further replies.

heatherci

Technical User
Feb 23, 2008
12
US
Hi,

I want to disable entry into a form field based on the entry of a prior field. For example, if the person enters "A","B" or "C" into field [TASK], then the [COUNT] field is disabled or will not accept data. (This also could just default to "0") If the selection in [TASK] is "D" or "E" I would like it to require an entry into [COUNT].

Thanks,

Heather
 
A word of advice, you shouldn't use words like Count as field names. Count is an aggregate function within Access. Using reserve words may lead to strange happenings later on.

On the AfterUpdate Event of Task, you could put:
If (Me![Task].Value = "D") Or (Me![Task].Value = "E")Then
Me![Count].Enabled = True
Else
Me![Count].Enabled = False
End IF

And to be sure it's disabled when the form opens, put
Me![Count].Enabled = False on the OnOpen event.

You can validate data entry into [Count] on the BeforeUpdate event of the form if [Task] is D or E.

To see what the properties mean, click in the box next to them on the property sheet and hit F1. You'll see examples.
 
or
Code:
[blue]   Me!Count.Enabled = ((Me!Task = "D") Or (Me!Task = "E"))[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Thank you to both of you. The field is not really named "COUNT" but just a quick way to type up my dilemma. Thanks for the info though. I will give this a shot in the morning. Could I also add some code so that it is not visible until those Enabling tasks are chosen?

 
heatherci . . .

Change [blue].Enabled[/blue] to [blue].Visible[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
I like those kind of answers. I have some that will still try to enter info even if it was disabled which might generate some unnecessary calls to me telling me its broke. I think hiding it may be the better route as I think outloud here. Simple is best. Thanks for your help.
 
Hi, the code worked fine except it was for a continous subform so when enabled or visible it would revert all the records on the subform to the same status so here is what my friend suggested and assisted me with. I don't have the exact code at home but we ended up using a Select Case stmt that involved unlocking the [Minutes] cells based on the [TASKID] criteria and locking the [Minutes] and setting the field to "0" if the criteria wasn't met and locking the records on form current. All is working wonderful but it seems to have goofed up my DUPLICATE RECORD button which was created from the wizard. I believe the "LOCK" on form current is preventing the record from duplicating. It will let me do a manual copy and paste though. The code appends a blank row each time its clicked as opposed to duplicating the current record. I have tried changing the code on the command to
RUNCOMMAND rncmdselectrecord
RUNCOMMAND runcmdcopy
RUNCOMMAND runcmdappendsomething. Still does not work unless I remove the Select Case stmt. Any suggestions?
 
heatherci . . . What you need is [blue]Conditional Formatting[/blue]!
[ol][li]Remove or disable any code you have to handle this.[/li]
[li]Open the form in [blue]design view[/blue] and select the [blue]count[/blue] field (or what ever its name is).[/li]
[li]Then select from the menubar [blue]Format[/blue] - [blue]Conditional Formatting ...[/blue]. You should be in the conditional formatting window![/li]
[li]In the combobox on the left select [blue]Expression Is[/blue].[/li]
[li]In the box just to the right of the combo, copy/paste the following:
Code:
[blue][Task]="a" Or [Task]="b" Or [Task]="c"[/blue]
[/li]
[li]Click the disable button
ConFmtEnBut.BMP
on the button right.[/li]
[li]Click [blue]OK[/blue] and perform your testing![/li][/ol]
[blue]Your Thoughts? . . .[/blue]



Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Hi Aceman,

I did try that in different ways but not with the coding disabled. I was trying to black it out and even blend it into the background as much as possible so it didn't look like it existed so even if they did try to enter they would not see it and eventually quit trying. I'll try it tomorrow when I go to work. Thanks.
 
heatherci . . .

In my prior post:

6. . . . . . on the button right.
should've been
6. . . . . . on the [blue]bottom[/blue] right.

Also, with the textbox [blue]disabled[/blue] it doesn't matter if they can see it or not! They can't edit! Whereas blending into the background [blue]allows editing[/blue], even though they can't see . . .



Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Hi,

I did the conditional formatting with the box enabled by the criteria. I did also have to add a second stmt that disabled based on the not equal to criteria to disable the box as opposed to disabling on Form open. This way allows the duplicate command to work with no issues at all. THe database is done and out and they are happy now. Thanks so much for your help. Its over and done and I'm on to finish my other ones. I have one Access database that has taken on a life of its own that I need to web base soon. I have them accessing it now through a .bat file and have been pretty lucky for the last 2 years that it hasn't corrupted(knock on wood). We are looking into Visual Studio. Any recommendations?

Heather
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top