A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Greyout a field (textbox on a form) using a checkbox????



 
 
Thread Tools Display Modes
  #11  
Old January 18th, 2005, 04:33 PM
Ben Radford via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

any ideas why it isn't working?

The OnClick works I think its to do with the OnCurrent

Ben

--
Message posted via http://www.accessmonster.com
  #12  
Old January 18th, 2005, 06:12 PM
Bruce M. Thompson
external usenet poster
 
Posts: n/a
Default

any ideas why it isn't working?

Did you make sure that the object names match those in your project? Post your
code (the full procedure including the "Private Sub" and the "End Sub" for both
the "On Click" event procedure and the "On Current" event procedure.

The OnClick works I think its to do with the OnCurrent


There must be a difference in the code between the two procedures

--
Bruce M. Thompson, Microsoft Access MVP
(See the Access FAQ at http://www.mvps.org/access)
NO Email Please. Keep all communications

within the newsgroups so that all might benefit.


  #13  
Old January 19th, 2005, 09:34 AM
Ben Radford via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

This is the code for the 'greyout' of the EmailAddress field on the form:

Private Sub Yesno_email_Click()

Me.EmailAddress_textbox.Enabled = (Not Me.Yesno_email)


End Sub

And this works fine. But this bit dosen't work -

Private Sub Form_Current()

Me!txtEmailAddress.Enabled = Me!chkEmail_YesNo

End Sub

I put it in the OnCurrent for the check box but an error message comes up saying debug etc. Do I have to replace the other code with the new one or use both of them together??

cheers Ben

--
Message posted via http://www.accessmonster.com
  #14  
Old January 19th, 2005, 11:24 AM
Brendan Reynolds
external usenet poster
 
Posts: n/a
Default

One possibility is that the text box may have the focus when the code in the
current event runs. You can't disable a control while it has the focus. Try
moving the focus to the check box (or another control on the form if you
prefer) before attempting to disable the text box ...

Private Sub Form_Current()

Me!chkEmail_YesNo.SetFocus
Me!txtEmailAddress.Enabled = (Me!chkEmail_YesNo)

End Sub

Note also the parentheses I've placed around the reference to the check box
control. There was a bug in at least some versions of Access that could
cause Access to fail to close properly if you had an implicit reference to
the value of a check box in the code, and using parentheses like this is one
method of avoiding that bug. I don't know if the bug persists in recent
versions, so the parentheses may not be essential, but they certainly won't
hurt.

If this doesn't solve the problem, tell us what the error message says.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.


"Ben Radford via AccessMonster.com" wrote in
message news:22d9f592e0e247be9060b068ed365e9d@AccessMonste r.com...
This is the code for the 'greyout' of the EmailAddress field on the form:

Private Sub Yesno_email_Click()

Me.EmailAddress_textbox.Enabled = (Not Me.Yesno_email)


End Sub

And this works fine. But this bit dosen't work -

Private Sub Form_Current()

Me!txtEmailAddress.Enabled = Me!chkEmail_YesNo

End Sub

I put it in the OnCurrent for the check box but an error message comes up
saying debug etc. Do I have to replace the other code with the new one or
use both of them together??

cheers Ben

--
Message posted via http://www.accessmonster.com



  #15  
Old January 19th, 2005, 04:44 PM
Ben Radford via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

still no joy I'm afraid, this is what the error message says -

Run-time error '2465':

MS Access can't find the the field 'chkYesno_email' referred to in your expression.

etc etc

Ben

--
Message posted via http://www.accessmonster.com
  #16  
Old January 19th, 2005, 06:52 PM
Jeff Conrad
external usenet poster
 
Posts: n/a
Default

Ben,

I believe the root of the problem is that you are just copying/pasting the code given
to you by Brendan and Bruce, but not making changes to account for *your* actual control names.

This is exactly what you posted in an earlier message:
Begin Quote:

This is the code for the 'greyout' of the EmailAddress field on the form:

Private Sub Yesno_email_Click()

Me.EmailAddress_textbox.Enabled = (Not Me.Yesno_email)

End Sub

And this works fine. But this bit dosen't work -

Private Sub Form_Current()

Me!txtEmailAddress.Enabled = Me!chkEmail_YesNo

End Sub

End Quote

Do you see the difference in CONTROL names?
In one spot you have EmailAddress_textbox and the other txtEmailAddress.
For the check box you have Yesno_email in one spot and chkEmail_YesNo in the other.

Access is totally confused right now!
Brendan then provided this bit of code:
Begin Quote:

Private Sub Form_Current()

Me!chkEmail_YesNo.SetFocus
Me!txtEmailAddress.Enabled = (Me!chkEmail_YesNo)

End Sub

End Quote

You then said:
Run-time error '2465':

MS Access can't find the field 'chkYesno_email' referred to in your expression.


Do you see the issue?
If you just copied the code, but did not adjust it for your actual control names,
then Access naturally cannot find the control you are referring to.
Step back a minute and take a hard look at the code and make adjustments
for the control names you actually have.

So ***IF*** your two controls are named:
EmailAddress_textbox
Yesno_email

then Brendan's code should look like this in the Current event of the form:

Private Sub Form_Current()

Me!Yesno_email.SetFocus
Me!EmailAddress_textbox.Enabled = (Me!Yesno_email)

End Sub

BUT, double check the control names first!
If you are still having problems, please post back with the
actual control names on the form.

BTW, for future reference, it is usually good practice to avoid having spaces in control names

--
Jeff Conrad
Access Junkie
Bend, Oregon

"Ben Radford via AccessMonster.com" wrote in message
news:abf6e84c55e541929bc971c78a3ec4d4@AccessMonste r.com...
still no joy I'm afraid, this is what the error message says -

Run-time error '2465':

MS Access can't find the the field 'chkYesno_email' referred to in your expression.

etc etc

Ben

--
Message posted via http://www.accessmonster.com



  #17  
Old January 19th, 2005, 09:48 PM
Bruce M. Thompson
external usenet poster
 
Posts: n/a
Default

still no joy I'm afraid, this is what the error message says -

Run-time error '2465':

MS Access can't find the the field 'chkYesno_email' referred to in your
expression.


Jeff hit the nail on the head. You need to make sure that the line of code you
are using is the same in both the "OnClick" event procedure of the control and
the form's "OnCurrent" event procedure. You specified that the following worked
in the control's code:

Me.EmailAddress_textbox.Enabled = (Not Me.Yesno_email)

So, just use that same line in the form's "OnCurrent" event procedure.

--
Bruce M. Thompson, Microsoft Access MVP
(See the Access FAQ at http://www.mvps.org/access)
NO Email Please. Keep all communications

within the newsgroups so that all might benefit.


  #18  
Old January 19th, 2005, 09:57 PM
Bruce M. Thompson
external usenet poster
 
Posts: n/a
Default

Me.EmailAddress_textbox.Enabled = (Not Me.Yesno_email)

Er ... that should be:

Me.EmailAddress_textbox.Enabled = (Not Me.Yesno_email.Value)
....or...
Me.EmailAddress_textbox.Enabled = Not (Me.Yesno_email)

Brendan caught that one earlier and I'm reinforcing his suggestion to avoid the
"boolean bug". g

--
Bruce M. Thompson, Microsoft Access MVP
(See the Access FAQ at http://www.mvps.org/access)
NO Email Please. Keep all communications

within the newsgroups so that all might benefit.


  #19  
Old January 20th, 2005, 10:13 AM
Ben Radford via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

Thanks guys you were quite right, I didn't realise that txt and textbox meant the same thing, oh well you learn something new everyday. Now theres a new problem. The EmailAddress field when told to 'greyout' and when you go to the next contact in the form the 'greyout' disapears however when you then return to the original contact the EmailAddress field doesn't greyout again, i.e its not display the greyout even though the check box is ticked. I was hoping to try and make contacts email addresses greyout depending on whether their 'unsubscribe' checkbox had been ticked. This is purley for a visual thing for users to see they have unsubscribed easily but I will set queries up for filtering/searching later. Anyone know what the problem might be? Sorry I'm not very good at VB... Many thanks for all you help up to this point btw, very kind of you....

Ben

--
Message posted via http://www.accessmonster.com
  #20  
Old January 20th, 2005, 07:50 PM
Bruce M. Thompson
external usenet poster
 
Posts: n/a
Default

Thanks guys you were quite right, I didn't realise that txt and textbox meant
the same
thing, oh well you learn something new everyday. Now theres a new problem. The
EmailAddress field when told to 'greyout' and when you go to the next contact
in the
form the 'greyout' disapears however when you then return to the original
contact the
EmailAddress field doesn't greyout again, i.e its not display the greyout even
though the
check box is ticked. I was hoping to try and make contacts email addresses
greyout
depending on whether their 'unsubscribe' checkbox had been ticked. This is
purley for a
visual thing for users to see they have unsubscribed easily but I will set
queries up for
filtering/searching later. Anyone know what the problem might be? Sorry I'm
not very
good at VB... Many thanks for all you help up to this point btw, very kind of
you....


Is your form displaying single records or continuous records (multiple records
can be seen on the screen at one time)? This technique does not work very well
with continuous forms because the focus can be on a different record than the
one you are viewing. The record with the focus (the "current" record) will
determine the enabled state of the textbox, so in continuous mode all instances
of the textbox will be either enabled or not depending on the value of the
"unsubscribe" checkbox in the "current" record. If you click on the record you
are currently viewing in continuous view, the enabled state should be
appropriate for that record.

If the above doesn't describe what you are experiencing, let us know.

--
Bruce M. Thompson, Microsoft Access MVP
(See the Access FAQ at http://www.mvps.org/access)
NO Email Please. Keep all communications

within the newsgroups so that all might benefit.


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form will not let me click in the checkbox field TAWise Using Forms 1 January 16th, 2005 01:55 AM
How to get a field on a form to reflect a certain record of a query? General Discussion 0 December 11th, 2004 12:56 AM
Need to clear controls of Filter form Jan Il Using Forms 2 November 28th, 2004 02:04 PM
Cursor Positioning Colin Hammond General Discussion 3 November 2nd, 2004 08:42 PM
Inserting checkbox form field without the brackets Michael Pompey New Users 1 April 26th, 2004 03:56 PM


All times are GMT +1. The time now is 02:02 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.