I will try to make this short. Again I have the form for Exercise Logs.
Attachment 60950
When the form loads the check box for the day of the week is enabled and checked. I do that like this;
This is the function that sets the day of the week;Code:' check the day of the week so that is the only check box available to the user ' declare a variable to get the day of the week Dim DayOfWeek = Now.ToLongDateString ' declare a variable to get today ' break apart the string and get only the day Dim todaysDate As String = DayOfWeek Dim ThisDay As String = String.Empty ThisDay = todaysDate.Substring(0, todaysDate.IndexOf(" "c)).Replace(",", String.Empty).Trim Dim thisDayNow As String = ThisDay ' call the function WhatDay passing in the day of the week to ' set the check box of the weekday to enabled WhatDay(thisDayNow)
Then to enable the appropriate day I do this;Code:Private Function WhatDay(ByVal TheDay As String) As String If TheDay = "Sunday" Then Me.cbxSunday.Enabled = True ElseIf TheDay = "Monday" Then Me.cbxMonday.Enabled = True ElseIf TheDay = "Tuesday" Then Me.cbxTuesday.Enabled = True ElseIf TheDay = "Wednesday" Then Me.cbxWednesday.Enabled = True ElseIf TheDay = "Thursday" Then Me.cbxThursday.Enabled = True ElseIf TheDay = "Friday" Then Me.cbxFriday.Enabled = True ElseIf TheDay = "Saturday" Then Me.cbxSaturday.Enabled = True End If Return TheDay End Function
I check the radio button Yes or No after asking if the user has exercised today.Code:Sub checkCheckBox() Dim ctrl As Control = Me.GetNextControl(Me, True) While ctrl IsNot Nothing If TypeOf ctrl Is CheckBox And ctrl.Enabled = True Then DirectCast(ctrl, CheckBox).Checked = True End If ctrl = Me.GetNextControl(ctrl, True) End While End Sub
What I would like to do is if Yes is checked, then the day of the week is checked, if No is checked then nothing happens.
Is this not valid?
Code:Sub checkCheckBox() Dim ctrl As Control = Me.GetNextControl(Me, True) While ctrl IsNot Nothing If TypeOf ctrl Is CheckBox And ctrl.Enabled = True And Me.rbtnYes.Checked = True Then DirectCast(ctrl, CheckBox).Checked = True Else DirectCast(ctrl, CheckBox).Checked = False End If ctrl = Me.GetNextControl(ctrl, True) End While End Sub
If not is there a way to correct it?
Thanks
CoachBarker




Reply With Quote