Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best Way to Write Function 2

Status
Not open for further replies.

LouieGrandie

Technical User
Mar 3, 2011
136
0
0
US
Have a field SelectionsYesNo which will a value of either Yes or No I want the following fields to be enabled if the value is Yes otherwise Disabled.

SelectionsOwner
SelectionsEstimatedTime
SelectionsEDC
SelectionsCompletedDate
SelectionsStartDate

I intend to put this statement on AfterUpdate on SelectionsYesNo. What is the best way to write that?


Visit Sage's Online Community
 
Me!SelectionsOwner.Ebabled = Me!SelectionsYesNo
Me!SelectionsEstimatedTime.Ebabled = Me!SelectionsYesNo
Me!SelectionsEDC.Ebabled = Me!SelectionsYesNo
Me!SelectionsCompletedDate.Ebabled = Me!SelectionsYesNo
Me!SelectionsStartDate.Ebabled = Me!SelectionsYesNo

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi LouieGrandie,


You could simplify using a WITH statement:

With Me
!SelectionsOwner.Enabled = !SelectionsYesNo
!SelectionsEstimatedTime.Enabled = !SelectionsYesNo
!SelectionsEDC.Enabled = !SelectionsYesNo
!SelectionsCompletedDate.Enabled = !SelectionsYesNo
!SelectionsStartDate.Enabled = !SelectionsYesNo
End With

 
There is no real 'best way'. Endless opportunities. I would suggest adding a variable,

Code:
 Dim boolYesNo As boolean

 With Me
 boolYesNo = !SelectionsYesNo
 !SelectionsOwner.Enabled = boolYesNo
 !SelectionsEstimatedTime.Enabled = boolYesNo
 !SelectionsEDC.Enabled = boolYesNo
 !SelectionsCompletedDate.Enabled = boolYesNo
 !SelectionsStartDate.Enabled = boolYesNo
 End With

The minor advantage here is the minimizing references to the (form) variable !SelectionYesNo This may seem (ie) trivial here, but coluld be important is a larger scope.



MichaelRed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top