Consulting

Results 1 to 2 of 2

Thread: Userform with calendar month code to bold 2 inputbox result day label value

  1. #1
    VBAX Expert mperrah's Avatar
    Joined
    Mar 2005
    Posts
    744
    Location

    Userform with calendar month code to bold 2 inputbox result day label value

    Hello,
    I have a userform to track monthly bills.
    I have radial buttons to make Bold the day of the week of pay day. 4 options:
    Off, Fridays, Every other Friday and Bitmonthly (user input box one for each day)
    The code works except every day becomes bold instead of just the 2 input values.
    Not sure what I'm I have done wrong.

    Any help is much appreciated.

    Sub pd_BiMonth() ' bi monthly'makes the nD1 and nD2 text input entries day captions Bold when the check box is active
    Dim D, x As Integer
    Dim nD1 As Variant
    Dim nD2 As Variant
    Dim myDate As Date
    
    
        With ufCal
            nD1 = InputBox("Please enter the day of the month your first payday lands on", "First PayDay of Month")
                If nD1 = "" Then Exit Sub
            nD2 = InputBox("Please enter the day of the month your second payday lands on", "Second PayDay of Month")
                If nD2 = "" Then Exit Sub
            For x = 1 To 42
                .Controls("dnum" & x).Font.Bold = False
                .Controls("dnum" & x).Font.Size = 9
            Next x
            
            myDate = .uMonth.Caption & "-1-" & .uYear.Caption
       
            D = FirstWeekDayOfMonth(myDate) - 1
                
                .Controls("dnum" & D + nD1).Font.Bold = .ob_BiMonth.Value
                .Controls("dnum" & D + nD1).Font.Size = 11
            
                .Controls("dnum" & D + nD2).Font.Bold = .ob_BiMonth.Value
                .Controls("dnum" & D + nD2).Font.Size = 11
        End With
    End Sub
    This is the code for every other friday, works fine
    Sub pd_EoF()
    
    Dim wknm As Date
    Dim mywk As Long
    Dim x, j As Long
    
    
    With ufCal
    
    
     For j = 1 To 42
            .Controls("dnum" & j).Font.Bold = False
            .Controls("dnum" & j).Font.Size = 9
        Next j
    
    
        For x = 6 To 41 Step 7
            If .Controls("dnum" & x).Caption <> "" Then
                wknm = .uMonth.Caption & "-" & .Controls("dnum" & x).Caption & "-" & .uYear.Caption
                mywk = myWeekNum(wknm)
                If wknm Mod 2 = 1 Then
                    .Controls("dnum" & x).Font.Bold = .ob_EoF.Value
                    .Controls("dnum" & x).Font.Size = 11
                End If
            End If
        Next x
    End With
    
    
    End Sub
    Last edited by mperrah; 05-17-2021 at 09:21 AM. Reason: added explination

  2. #2
    VBAX Expert mperrah's Avatar
    Joined
    Mar 2005
    Posts
    744
    Location
    I keep trying different scenarios and came up with this. Seems to work so far.
    Hope I didn't waste your time.
    Thank you for listening. Hope this helps someone else too.
    Sub pd_BiMonth() ' bi monthly'makes the nD1 and nD2 text input entries day captions Bold when the check box is active
    Dim D, x As Integer
    Dim nD1 As Variant
    Dim nD2 As Variant
    Dim myDate As Date
    
    
        With ufCal
            nD1 = InputBox("Please enter the day of the month your first payday lands on", "First PayDay of Month")
                If nD1 = "" Then Exit Sub
            nD2 = InputBox("Please enter the day of the month your second payday lands on", "Second PayDay of Month")
                If nD2 = "" Then Exit Sub
                
             myDate = .uMonth.Caption & "-1-" & .uYear.Caption
       
             D = FirstWeekDayOfMonth(myDate) - 1
             
             D1 = D + nD1
             D2 = D + nD2
             
            For x = 1 To 42
                If x = D1 Or x = D2 Then
                .Controls("dnum" & x).Font.Bold = True
                .Controls("dnum" & x).Font.Size = 11
                Else
                .Controls("dnum" & x).Font.Bold = False
                .Controls("dnum" & x).Font.Size = 9
                End If
            Next x
                
        End With
    End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •