Question

I created a Monthview and TimePicker in a form. I want the user to pick the time, and select a month which will bold the value selected each time, then select OK which will insert the value. I have all of this working fine. The issue is that if a user selects a date, then selects another date, or another date, all the dates are getting Bolded. I want the BOLD to only follow each most recent click.. if that makes sense, so that the user knows what value he chose.

Here is my click code:

  Private Sub MonthView1_DateClick(ByVal DateClicked As Date)

 Dim x As Date

    x = MonthView1.value
    MonthView1.DayBold(x) = True ' Bold the date

End Sub

What method do I need? Is there some kind of most-recent clicked property?

Was it helpful?

Solution

Try the following code:

Private Sub MonthView1_DateClick(ByVal DateClicked As Date)

Dim x As Date
Dim MaxDate As Date
Dim MinDate As Date

MinDate = DateSerial(Year(DateClicked), Month(DateClicked), 1) 'Get first date of current month based on clicked date
MaxDate = DateSerial(Year(DateClicked), Month(DateClicked) + 1, 0) 'Get last date of current month based on clicked date

x = ActiveCell.Value 'Retreive value of last Bold date
If x >= MinDate And x <= MaxDate Then 'If last Bold date is in the current month then unbold it
    MonthView1.DayBold(x) = False
End If

MonthView1.DayBold(DateClicked) = True 'Bold the clicked date
ActiveCell.Value = DateClicked 'Store current date in a sheet

End Sub

The idea is to save the Bold date in a sheet (you may hide it if you wish) and retrieve it when another date is selected. The Bold formatting is removed from the previous date and applied to the current one.

OTHER TIPS

a bit more on bolding in a MonthView

'<code>
Private Sub CommandButton1_Click()
  Dim Ss(50) As Boolean

  'put  in module  DaysToBold$  and DatesToBold$  as public variables
  DaysToBold = "713"  ' sat Sun Tue
  ' DaysToBold = "" ' for none
  DatesToBold = "x,1,2,12,22,30"
 ' DatesToBold = "x" ' if none

  MonthView21_GetDayBold Now, 49, Ss

End Sub

Private Sub MonthView21_GetDayBold(ByVal StartDate As Date, _
            ByVal Count As Integer, State() As Boolean)
  Dim I As Integer, Mi%, DTB, DI%, DAd%
  On Error Resume Next ' seem to be  negative indices into State() even if declared  ( -10 to 50)

  For Mi = 1 To Len(DaysToBold)  ' mark of the Days of week to bold
    I = Mid(DaysToBold, Mi, 1)  ' single digits 1 ..7  excel translate to integer
    While I < Count
        State(I - MonthView21.StartOfWeek) = True
        I = I + 7  ' down the column
    Wend
  Next Mi


  DTB = Split(DatesToBold, ",")
  If UBound(DTB) > 0 Then
    With MonthView21
        For I = 1 To UBound(DTB)  ' mark the date numbers to bold
          DI = Weekday(DateSerial(Year(.Value), Month(.Value), 1), .StartOfWeek)
         If DI = 1 Then DAd = 5 Else DAd = -2  ' 7 days of last month there if Di=1
            State(DTB(I) + DI + DAd) = True
        Next I
    End With
  End If
End Sub
'</code>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top