Clicky

Please can you help?

1.I'd like to amend the VB code so that txtHrs1, txtHrs2, txtMins1 and txtMins2 are restricted to only 2 characters on input.
2.Currently the user form brings back the value in Columns B, V, I or W on any given row.
3. If no date has been entered I would like for the textboxes to today’s date.
4.If the cell is currently empty, would it be possible to format the userform text to blue?  
Textbox1, Textbox2, Textbox3 & Textbox4
dev3.xls
  • 117 KB
  • help
dev3.xls

    asked 12/15/2011 06:05

    Kiwi-123's gravatar image

    Kiwi-123 ♦♦


    3 Answers:
    Amend Macro as below:
    1:
    2:
    3:
    4:
    5:
    6:
    7:
    8:
    9:
    10:
    11:
    12:
    13:
    14:
    15:
    16:
    17:
    18:
    19:
    20:
    21:
    22:
    23:
    24:
    25:
    26:
    27:
    28:
    29:
    30:
    31:
    32:
    33:
    34:
    35:
    36:
    37:
    38:
    39:
    40:
    41:
    42:
    43:
    44:
    45:
    Private Sub UserForm_Initialize()
    
    
        Set rngStart = Cells(ActiveCell.Row, "B")
        With rngStart
    
                TextBox1.Value = Format(.Value, "ddd dd/mm/yyyy")
                TextBox2.Value = Format(.Offset(, 7).Value, "ddd dd/mm/yyyy")
                TextBox3.Value = Format(.Offset(, 20).Value, "ddd dd/mm/yyyy")
                TextBox4.Value = Format(.Offset(, 21).Value, "ddd dd/mm/yyyy")
                txtHrs1.Value = Format(.Offset(, 7).Value, "HH")
                txtMins1.Value = Format(Minute(.Offset(, 7).Value), "00")
                txtHrs2.Value = Format(.Offset(, 21).Value, "HH")
                txtMins2.Value = Format(Minute(.Offset(, 21).Value), "00")
                TextBox5.Text = VBA.Environ("USERNAME")
                
        End With
        '<------Begin of Insert
        '1.I'd like to amend the VB code so that txtHrs1, txtHrs2, txtMins1 and txtMins2 are restricted to only 2 characters on input.
        txtHrs1.MaxLength = 2
        txtHrs2.MaxLength = 2
        txtMins1.MaxLength = 2
        txtMins2.MaxLength = 2
        '2.Currently the user form brings back the value in Columns B, V, I or W on any given row.
        '3.If no date has been entered I would like for the textboxes to today’s date.
        '4.If the cell is currently empty, would it be possible to format the userform text to blue
        'Textbox1, Textbox2, Textbox3 & Textbox4
        If TextBox1.Value = "" Then
            TextBox1.Value = Format(Now, "ddd dd/mm/yyyy")
            TextBox1.ForeColor = vbBlue
        End If
        If TextBox2.Value = "" Then
            TextBox2.Value = Format(Now, "ddd dd/mm/yyyy")
            TextBox2.ForeColor = vbBlue
        End If
        If TextBox3.Value = "" Then
            TextBox3.Value = Format(Now, "ddd dd/mm/yyyy")
            TextBox3.ForeColor = vbBlue
        End If
        If TextBox4.Value = "" Then
            TextBox4.Value = Format(Now, "ddd dd/mm/yyyy")
            TextBox4.ForeColor = vbBlue
        End If
        '<------End of Insert
    End Sub
    link

    answered

    wchh's gravatar image

    wchh

    1.I'd like to amend the VB code so that txtHrs1, txtHrs2, txtMins1 and txtMins2 are restricted to only 2 characters on input.
    --> You can also change Maxlength from 0 to 2 for textbox property.
    link

    answered 2011-12-15 at 15:29:04

    wchh's gravatar image

    wchh

    Many thanks for your help!
    link

    answered 2011-12-15 at 15:31:30

    Kiwi-123's gravatar image

    Kiwi-123

    Your answer
    [hide preview]

    Follow this question

    By Email:

    Once you sign in you will be able to subscribe for any updates here

    By RSS:

    Answers

    Answers and Comments

    Tags:

    Asked: 12/15/2011 06:05

    Seen: 197 times

    Last updated: 12/15/2011 08:33

    Related questions