Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / March 2005

Tip: Looking for answers? Try searching our database.

question regarding checkboxes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lauren B - 31 Mar 2005 15:55 GMT
I am attempting to have the status of a checkbox dictate what appears in a
particular text box.  I used to the following code:

If Checkbox = True Then
   Textbox = "Comment 1"
Else
   Textbox= "Comment 2"
End If
End Sub

I have a problem as a user may uncheck the checkbox; however, "Comment 1"
still needs to appear in the textbox.  Is there a way to write my code so
that "Comment 1" appears in the textbox if the checkbox is checked OR was
checked and then unchecked?  Comment 2 should only appear if the checkbox
was never checked.

Thank you for any assistance.

LB
John Vinson - 31 Mar 2005 18:29 GMT
>I am attempting to have the status of a checkbox dictate what appears in a
>particular text box.  I used to the following code:
[quoted text clipped - 11 lines]
>checked and then unchecked?  Comment 2 should only appear if the checkbox
>was never checked.

You'll need to store the value Comment 1 or Comment 2 in a table in
order for Access to "remember" whether it has EVER been changed.
Remember, a checkbox or a textbox on a form *is not* a data storage
medium - it's a data *display* medium! Data is stored in Tables, and
only in Tables.

That said, you can use code like this to do what you describe. I'm
assuming you're on a Form, with controls chkMyCheck bound to the
yes/no field in your table, and txtComment bound to the comment field.
Select chkMyCheck's AfterUpdate event, click the ... icon by it, and
invoke the Code Builder:

Private Sub chkMyCheck_AfterUpdate()
If Me!chkMyCheck = True Then
  Me!txtComment = "Comment 1"
End If
End Sub

If you set the Default Value property of txtComment to "Comment 2" new
records will be set to that value; the AfterUpdate event will
overwrite it if the user checks the checkbox, and leave it alone if
they clear it.

                 John W. Vinson[MVP]    
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.