By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,069 Members | 1,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,069 IT Pros & Developers. It's quick & easy.

greying out fields

P: 1
I'm a newbie at Access and am trying to get fields (like 'cs_compl', 'ec_compl', etc) in a form to grey out depending on the value entered into the 'type' field. However, 'type' is a calculated field dependent on the the value entered in the 'barcode' field. I'm using the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub barcode_AfterUpdate()
  2.     Me.cs_compl.Enabled = (Me.type.AfterUpdate <= 4 Or Me.type.AfterUpdate = 6 Or 7 Or 8)
  3.     cm_compl.Enabled = (Me.type.AfterUpdate <= 4 Or Me.type.AfterUpdate = 6 Or 7 Or 8)
  4.     ec_compl.Enabled = (4 <= Me.type.AfterUpdate >= 6)
  5.     Me.en_compl.Enabled = (Me.type.AfterUpdate = 1 Or 8)
  6.     Me.pe_compl.Enabled = (Me.type.AfterUpdate = 3 Or 4)
  7.     Me.uf_compl.Enabled = (Me.type.AfterUpdate = 3)
  8.     Me.ad_compl.Enabled = (4 <= Me.type.AfterUpdate >= 6)
  9. End Sub
Thanks for any advice!
Dec 9 '11 #1
Share this Question
Share on Google+
2 Replies


NeoPa
Expert Mod 15k+
P: 31,709
Unfortunately, you don't include the logic you want implemented in your question, but I'll try to reverse engineer this code and see what I can come up with. Next time please remember to ask the whole question fully if you'd like someone to spend their time trying to help you.

Try this :

Expand|Select|Wrap|Line Numbers
  1. Private Sub Barcode_AfterUpdate()
  2.     With Me
  3.         .cs_compl.Enabled = (.Type <= 4) Or _
  4.                             (.Type = 6) Or _
  5.                             (.Type = 7) Or _
  6.                             (.Type = 8)
  7.         .cm_compl.Enabled = .cs_compl.Enabled
  8.         .ec_compl.Enabled = (.Type >= 4) And (.Type <= 6)
  9.         .en_compl.Enabled = (.Type = 1) Or (.Type = 8)
  10.         .pe_compl.Enabled = (.Type = 3) Or (.Type = 4)
  11.         .uf_compl.Enabled = (.Type = 3)
  12.         .ad_compl.Enabled = .ec_compl.Enabled
  13.     End With
  14. End Sub
If it works, look at the code and see why.
Dec 9 '11 #2

TheSmileyCoder
Expert Mod 100+
P: 2,321
2 things you seem to have misunderstood:
Me.type.AfterUpdate is not the value of the textbox Type, after it is updated. Me.type.AfterUpdate is a PROPERTY, the same property that you can see specified in the Events TAB of your control. In your case it might read [EVENT PROCEDURE]

Second you make a comparison:
Expand|Select|Wrap|Line Numbers
  1. Me.type.AfterUpdate = 6 Or 7 Or 8
Which should further to the above have looked:
Expand|Select|Wrap|Line Numbers
  1. Me.type = 6 Or 7 Or 8
or
Expand|Select|Wrap|Line Numbers
  1. Me.type.Value= 6 Or 7 Or 8
The .Value is not necessary as .Value is the default property of the control.

Not quite done yet. Another (common) misunderstanding is that your code will compare Me.type to 6, 7 and 8. What really is happening is that you are comparing Me.type to 6, and then using the or operator between your comparision (which will be true or false) and 7 and 8. For the program it would look like this:
Expand|Select|Wrap|Line Numbers
  1. TRUE or 7 or 8
  2. FALSE or 7 or 8
To make the correct comparision that I believe you are after you should use:
Expand|Select|Wrap|Line Numbers
  1. Me.type = 6 Or Me.type = 7 Or Me.type = 8
or of course the code that NeoPa have provided for you.
Dec 12 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.