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

Questions about Access 2000 & forms

P: 3
good morning guys,

I have a Form composed of the following fields named:

"YY" (checkbox)
"X1", "X2", "X3" (datefields).

The question is: how can I manage the fields X1,X2,X3 so that they must be enabled only when checkbox "YY" is checked (true) ??

Please, could anybody give me the specific instructions to resolve the problem ??

Thank you very much in advance.

bye, Sandro54
Jan 27 '08 #1
Share this Question
Share on Google+
6 Replies


convexcube
P: 47
Good morning Guys,

I have a form of Access 2000 composed of the following fields named:

"YY" (checkbox)

"X1", "X2", "X3" (datefields).

The OS is Windows XP.

The question is: how can I manage the fields X1;X2;X3 so that they must be enabled only when checkbox "YY" is checked (true) ??.

Please, could anybody give me the specific instructions to resolve the problem ??

Thank you very much in advance.

bye
Sandro54
Hi Sandro,

To make the textboxes X1, X2 & X3 only able to accept data entry when Checkbox YY has been checked:
  1. Set all the textboxes enabled properties to false.
  2. Use the click event of Checkbox YY to switch the enabled property of the X Checkboxes with this code:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub YY_Click
    2.     If YY = True Then
    3.         X1.Enabled = True
    4.         X2.Enabled = True
    5.         X3.Enabled = True
    6.     Else
    7.         X1.Enabled = False
    8.         X2.Enabled = False
    9.         X3.Enabled = False
    10.     End If
    11. End Sub
This will prevent data entry when every checkbox YY is unchecked.

Hope this helps.

Kind Regards,
Ken Farrawell.
Jan 27 '08 #2

missinglinq
Expert 2.5K+
P: 3,532
When writing this kind of code, you also need to place it in the Form_Current event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. If YY = True Then
  3.  
  4.   X1.Enabled = True
  5.  
  6.   X2.Enabled = True
  7.  
  8.   X3.Enabled = True
  9.  
  10. Else
  11.  
  12.   X1.Enabled = False
  13.  
  14.   X2.Enabled = False
  15.  
  16.   X3.Enabled = False
  17.  
  18. End If
  19.  
  20. End Sub
  21.  
With the code only in the OnClick event, if you check YY on Record A, it enables the textboxes. If you then move to Record B, the textboxes will still be enabled, even if YY on this record is unchecked! Running the code in Form_Current addresses this problem.

Welcome to TheScripts, Sandro54!

Linq ;0>
Jan 27 '08 #3

Expert 100+
P: 446
Hi Sandro54
The simplest way is to run some code in the On_Current event of the form
Expand|Select|Wrap|Line Numbers
  1. If Me!YY = True Then
  2.     Me!X1.Enabled = True
  3.     Me!X2.Enabled = True
  4.     Me!X3.Enabled = True
  5. Else
  6.     Me!X1.Enabled = False
  7.     Me!X2.Enabled = False
  8.     Me!X3.Enabled = False
  9. End If
However, if you check or uncheck 'YY' you will probably want an immediate result, so paste the same code into the After_Update event of 'YY'.

This will meet the requirement of your question but it will 'grey-out' the dis-abled fields, which might be OK for you but you might want to consider an alternative;
locking the fields and changing the back-colour. The following code will make the fields 'pale yellow' when locked but white when unlocked to recieve data.

Expand|Select|Wrap|Line Numbers
  1. Dim lngLocked as Long
  2. lngLocked = 8454143   'pale yellow
  3.  
  4. If Me!YY = True Then
  5.     Me!X1.Locked= False
  6.     Me!X2.Locked= False
  7.     Me!X3.Locked= False
  8.     Me!X1.Backcolor = vbWhite
  9.     Me!X2.Backcolor = vbWhite
  10.     Me!X3.Backcolor = vbWhite
  11. Else
  12.     Me!X1.Locked= True
  13.     Me!X2.Locked= True
  14.     Me!X3.Locked= True
  15.     Me!X1.Backcolor = lngLocked
  16.     Me!X2.Backcolor = lngLocked
  17.     Me!X3.Backcolor = lngLocked
  18. End If
If you have more than three fields you may want to write two seperate sub-routines 'LockFields' and 'UnLockField'
Expand|Select|Wrap|Line Numbers
  1. Private Sub LockFields()
  2. Dim lngLocked as Long
  3. lngLocked = 8454143   'pale yellow
  4.  
  5.     Me!X1.Locked= True
  6.     Me!X2.Locked= True
  7.     Me!X3.Locked= True
  8.     Me!X1.Backcolor = lngLocked
  9.     Me!X2.Backcolor = lngLocked
  10.     Me!X3.Backcolor = lngLocked
  11. end sub
You can write your own Unlock sub., then the code On_Current would be
Expand|Select|Wrap|Line Numbers
  1. If Me!YY = True Then
  2.    UnlockFields
  3. Else
  4.    LockFields
  5. Endif
I hope thi shelps

S7
Jan 27 '08 #4

missinglinq
Expert 2.5K+
P: 3,532
Sandro54: You posted this question twice this morning, 18 minutes apart, and thus have wasted the time of some of our members! Double posting is strictly forbidden here as it is on all forums! Please refrain from this behavior in the future!

From FAQs

Do Not Double Post Your Questions

Double posting is where you start a thread on a topic and then for some reason start another thread on exactly the same topic in the same forum. Please do not do this because

1. It makes it very hard for people to answer you especially if there are answers happening in all the threads you have started because they have to read 2 or more threads in order to see what has already been said.
2. It swamps the forum with your problem resulting in less attention for the other threads.

If you feel for some reason that you post has been overlooked (for instance it hasn't had any replies) please do not repost the question. Post a message to the thread you started, this will bump it back to the top of the thread list for the forum.

Thank you for your attention in this matter.

Linq ;0)>

Moderator
Jan 27 '08 #5

P: 3
Sandro54: You posted this question twice this morning, 18 minutes apart, and thus have wasted the time of some of our members! Double posting is strictly forbidden here as it is on all forums! Please refrain from this behavior in the future!

From FAQs

Do Not Double Post Your Questions

Double posting is where you start a thread on a topic and then for some reason start another thread on exactly the same topic in the same forum. Please do not do this because

1. It makes it very hard for people to answer you especially if there are answers happening in all the threads you have started because they have to read 2 or more threads in order to see what has already been said.
2. It swamps the forum with your problem resulting in less attention for the other threads.

If you feel for some reason that you post has been overlooked (for instance it hasn't had any replies) please do not repost the question. Post a message to the thread you started, this will bump it back to the top of the thread list for the forum.

Thank you for your attention in this matter.

Linq ;0)>

Moderator

I apologize for having submitted the same question twice. This is the first time I used your forum and I were not sure where to insert a new post and therefore I erroneously initiated a new discussion before discovering where to place the post. Again, my apologies.
Anyway thanks a lot for your invaluable support.
Jan 28 '08 #6

P: 3
Hi Sandro,

To make the textboxes X1, X2 & X3 only able to accept data entry when Checkbox YY has been checked:
  1. Set all the textboxes enabled properties to false.
  2. Use the click event of Checkbox YY to switch the enabled property of the X Checkboxes with this code:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub YY_Click
    2.     If YY = True Then
    3.         X1.Enabled = True
    4.         X2.Enabled = True
    5.         X3.Enabled = True
    6.     Else
    7.         X1.Enabled = False
    8.         X2.Enabled = False
    9.         X3.Enabled = False
    10.     End If
    11. End Sub
This will prevent data entry when every checkbox YY is unchecked.

Hope this helps.

Kind Regards,
Ken Farrawell.

Thank you for your assistance on this problem, it helped me a lot.
Jan 28 '08 #7

Post your reply

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