If checkbox checked, then grey out text fields

bsnapool

Registered User.
Local time
Today, 12:31
Joined
Nov 17, 2006
Messages
96
Hi All

this is my first post.....

I was wondering whether som one could point me in the right direction with this?

I am looking for when the checkbox field is ticked then this will grey out all text fields within the form for that record.

Any ideas?

Thanks in advance

Andrew
 
If the checkbox will store the info in the table for each record, then you can do this:

1. Put a Tag (find Tag in properties for each control you want to disable) like "disable" without the quotes.

2. In the OnCurrent event of the form do this:
Code:
Dim ctl As Control
If YourCheckBoxNameHere Then
For each ctl in Me.Controls
If ctl.Tag = "disable" Then
  ctl.Enabled = False
End If
Next ctl
Else
For each ctl in Me.Controls
If ctl.Tag = "disable" Then
  ctl.Enabled = True
End If
Next ctl
End If

Then, in the after update event of the check box, you put the same code.
 
Hi

Sorry just replying now, but got off from work early yesterday and only just had chance to reply.

I have followed your instructions but nothing happens, no error messges. When the checkbox is ticked, the fields which i have entered "disabled" without the quotes just stay the same...

Any ideas?
 
I just noticed that you said you put "disabled" into the TAG property, but the code I provided said "disable" and not "disabled."
 
just an observation

- it also depends whether you have locked the other controls on the form

you actually have two settings for these fields, which affect the display, and how you can interact with the fields - enabled and locked. Each can be true or false, so there are four combinations

enabled true
locked false -the "normal" setting, letting you use the control fully

enabled true
locked true -lets you into the control (eg to search and sort), but not edit the data

enabled false
locked true - displays the data, but you can't interact with it at all

and this is the one
enabled false
locked false - displays the data in a grayed field
 
Hi

Thanks for both of your replies....

My bad, when i said i put disabled i did actually put disable.

gemma-the-husky

I have tried your suggestions and it does not have any affect. when you say locked "true" this just doesnt allow any of the data to be edited and does not grey out the feild...

I have attached the example i have tried for you to have a look...

Any ideas would be really appreciated...

Thanks

Andrew
 
Apparently you didn't read the code too closely as the part that said:
YourCheckBoxNameHere
needs to be changed to your actual checkbox name.
 
My Bad...

Apologies! It working thanks very much, it works great.'

One slight issue, is when a new record is created a runtime error appears "94"

Invalid use of Null....

Any ideas to over come this?
 
Were would that go within this code:

Code:
Dim ctl As Control
If YourCheckBoxNameHere Then
For each ctl in Me.Controls
If ctl.Tag = "disable" Then
  ctl.Enabled = False
End If
Next ctl
Else
For each ctl in Me.Controls
If ctl.Tag = "disable" Then
  ctl.Enabled = True
End If
Next ctl
End If
 
it depends what you want to do.

your code is setting various fields as grayd or not, depending on the state of a particular text box.

the problem is, is that when you enter a new record, the check box you are using to test is neither true nor false but null.

using an nz will effectively force it to be treated as true or false, which may not be what you want. therefore you need to decide how you want to deal with the fields in the oncurrent event, if you have a newrecord. You can test this with

if me.newrecord

--------------------------------
thinking about all of this, at the moment you are graying the fields or not, in the oncurrent event. If you actually click the check box, then presumably, all the affected fields should change their setting, so you ought to think about putting the same code in the check box afterupdate event.

Hope this makes sense
 
gemma-the-husky

Thanks for your replies and help with this...

I am still struggling to adopt this code and overcome the error. Forgive me but I am fairly new with VBA within access. I have tried the nz and it still comes up with an error.

Is there ant other appraoches you could suggest?
 
SOLVED

i added a default value of false which overcome the issue.

Thanks

Andrew
 
bsnapool,

Have a look at the attached sample, it uses Bob's code and I have added a small piece so that you can go to a new record and the "Null" message will not appear.
 

Attachments

John could I ask you to do me a favour? and send this as a mdb file to my hotmail account as duer to restrictions i cannot open zip files in work.

I have pm'd you my email address

Many thanks

Andrew
 
bsnapool,

Have a look at the attached sample, it uses Bob's code and I have added a small piece so that you can go to a new record and the "Null" message will not appear.

This is exactly what i was looking for although i am having difficulty using the routines on a tabbed form. Any Ideas?.
 
A tabbed form shouldn't work any differently. The tab control is just another control and all controls on it are not referenced any differently than if it weren't there. In other words, any controls on a tab control are referenced the same as if they were existing on the form by themselves and weren't on the tab control.

The tab control basically just controls viewing of the other controls. They are still on your main form, it just LOOKS like they are on a different form.

So, if that doesn't help, what difficulty are you actually having? What is the code you are using?
 
I dont kow why, but i closed down access and re started and it now works perfectly! Thanks Anyway
 

Users who are viewing this thread

Back
Top Bottom