Consulting

Results 1 to 5 of 5

Thread: Word Does Not Recognise Date As Value?

  1. #1
    VBAX Regular
    Joined
    Jun 2018
    Posts
    15
    Location

    Word Does Not Recognise Date As Value?

    Only a quick question hopefully. I have set a userform to only show certain textboxes if entries are made to a preceeding textbox. This seems to work at first as if i type into the first textbox then the following one becomes invisible which is what i want. However as soon as i use the / charachter the next textbox reappears and i cannot quite workout why?

    I was simply using
    If TextBox1.Vaule = True Then
    TextBox2.Visible = False

    My ultimate goal was to force a date into a certain format dd/mmmm/yy. However i have no datepicker and no option to include one from the Additional Controls or Reference so looks like i will just have to trust that people will enter a date correctly.

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Try:
    Private Sub TextBox1_Change()
    Me.TextBox2.Visible = (Me.TextBox1.Text = "")
    End Sub
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    If you want a VBA date picker, I quite like the one Trevor Eyre developed for Excel - https://trevoreyre.com/portfolio/excel-datepicker/
    It can easily be modified to work with Word VBA. Import the userform from the zip to your project and then create a module to hold the following code examples to make it work.
    You can then use the output from the form to fill your text box in whatever format you wish.

    Option Explicit
    
    Sub Test()
        MsgBox BasicCalendar(Date)
        'MsgBox AdvancedCalendar(Date)
        'MsgBox AdvancedCalendar2(Date)
    lbl_Exit:
        Exit Sub
    End Sub
    
    Function BasicCalendar(StartDate As Date) As String
    Dim oFrm As New CalendarForm
        BasicCalendar = oFrm.GetDate( _
                        SelectedDate:=StartDate, _
                        TodayFontColor:=RGB(255, 0, 0))
    lbl_Exit:
        Set oFrm = Nothing
        Exit Function
    End Function
    
    Function AdvancedCalendar(StartDate As Date) As String
    Dim oFrm As New CalendarForm
        AdvancedCalendar = oFrm.GetDate( _
                           SelectedDate:=StartDate, _
                           FirstDayOfWeek:=Monday, _
                           DateFontSize:=12, _
                           TodayButton:=True, _
                           OkayButton:=True, _
                           ShowWeekNumbers:=True, _
                           BackgroundColor:=RGB(243, 249, 251), _
                           HeaderColor:=RGB(147, 205, 2221), _
                           HeaderFontColor:=RGB(255, 255, 255), _
                           SubHeaderColor:=RGB(223, 240, 245), _
                           SubHeaderFontColor:=RGB(31, 78, 120), _
                           DateColor:=RGB(243, 249, 251), _
                           DateFontColor:=RGB(31, 78, 120), _
                           TrailingMonthFontColor:=RGB(155, 194, 230), _
                           DateHoverColor:=RGB(223, 240, 245), _
                           DateSelectedColor:=RGB(202, 223, 242), _
                           SaturdayFontColor:=RGB(0, 176, 240), _
                           SundayFontColor:=RGB(0, 176, 240), _
                           TodayFontColor:=RGB(0, 176, 80))
    lbl_Exit:
        Set oFrm = Nothing
        Exit Function
    End Function
    
    Function AdvancedCalendar2(StartDate As Date) As String
    Dim oFrm As New CalendarForm
        AdvancedCalendar2 = oFrm.GetDate( _
                            SelectedDate:=StartDate, _
                            DateFontSize:=11, _
                            TodayButton:=True, _
                            BackgroundColor:=RGB(191, 225, 192), _
                            HeaderColor:=RGB(87, 98, 52), _
                            HeaderFontColor:=RGB(255, 255, 255), _
                            SubHeaderColor:=RGB(191, 225, 192), _
                            SubHeaderFontColor:=RGB(55, 86, 35), _
                            DateColor:=RGB(242, 248, 238), _
                            DateFontColor:=RGB(87, 98, 52), _
                            SaturdayFontColor:=RGB(55, 86, 35), _
                            SundayFontColor:=RGB(55, 86, 35), _
                            TrailingMonthFontColor:=RGB(106, 163, 67), _
                            DateHoverColor:=RGB(198, 224, 180), _
                            DateSelectedColor:=RGB(191, 225, 192), _
                            TodayFontColor:=RGB(255, 0, 0), _
                            DateSpecialEffect:=fmSpecialEffectRaised)
    lbl_Exit:
        Set oFrm = Nothing
        Exit Function
    End Function
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    Or you can download the ready made Word template here which was developed in collaboration with Trevor.

    https://gregmaxey.com/word_tip_pages...cker_form.html
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    VBAX Regular
    Joined
    Jun 2018
    Posts
    15
    Location
    Thank you. I have implemented the first solution and the other two are in my favourites for the future version 2 of this document.

Posting Permissions

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