Consulting

Results 1 to 7 of 7

Thread: Input Date as Formatted

  1. #1

    Input Date as Formatted

    I'm attempting to have a user input a date into objTextBox and it must be formatted as ddmmmyy. If the date format is incorrect or something other than a date it'll post Invalid Date into objTextBox5. That part works but my code does not recognize the text objTextBox as a date entered in the format ddmmmyy to then paste into objTextBox3. Any help would be greatly appreciated, I'm a very novice VBA user and have wrecked my brain on this for many iterations lol figured it was time for help.

    Sub LnSelR2_Date()
    Dim objPresentaion As Presentation
    Dim objSlide As Slide
    Dim objTextBox As Shape
    Dim objTextBox3 As Shape
    Dim objTextBox5 As Shape


    Set objPresentaion = ActivePresentation
    Set objSlide = objPresentaion.Slides.Item(1)
    Set objTextBox = objSlide.Shapes.Item("TextBox1")
    Set objTextBox3 = objSlide.Shapes.Item("TextBox3")
    Set objTextBox5 = objSlide.Shapes.Item("TextBox5")


    If objTextBox.TextFrame.TextRange = Format(Date, "ddmmmyy") Then
    objTextBox.TextFrame.TextRange.Cut
    objTextBox3.TextFrame.TextRange.Paste
    Else
    objTextBox.TextFrame.TextRange.Cut
    objTextBox5.TextFrame.TextRange = "Invalid Date"
    End If


    End Sub

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I don't really do PP, but generally in VBA and MSForms, something like
    If IsDate(objTextBox.TextFrame.TextRange) Then
       objTextBox.TextFrame.TextRange= Format(objTextBox.TextFrame.TextRange, "ddmmmyy")
    Else
       objTextBox5.TextFrame.TextRange = "Invalid Date"
    End If
    If this doesn't help, at least it will serve to bump your query to the top of the list.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Are the textboxes ActivX textboxes added from the Developer Tab so that text can be entered during a slide show?
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4
    Quote Originally Posted by John Wilson View Post
    Are the textboxes ActivX textboxes added from the Developer Tab so that text can be entered during a slide show?
    No these are regular textboxes. Text is still being added during the slideshow via action button macros.

  5. #5
    I didn't get to test this just yet but thank you for the response. Any spark of new ideas has me hopeful because I was starting to just pull my hair lol.

  6. #6
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Generally, I let users enter Dates in any format they want, as long as IsDate recognizes it. All Dates in UserForm Controls and TextFrames are really just Strings of text anyway. I only convert the date Text to a Date Type as Code or Record keeping require. I only reformat Dates when Business Rules require. Ex: A DB Field requires Dates to be 6 characters.
    I notice that you're using three 'TextBoxes' to handle the Dates; One for Date Entry, One for Date Storage, and one for Format Warning.

    I suggest just the TextBox1 for both entry and display, a Variable to hold the actual Date, and an InValidDate Warning object of your choice from whatever PP offers. In MS Forms, I use a Label Control as the warning because they take the least memory. The only thing my warning says is
    Please enter a valid Date in the format of 4 July, 76.

    Click me to continue.
    Note that I don't hold them to that format, they can use any format they choose, as long as IsDate recognizes it. My code for this looks something similar to
    Dim ThatDate As Date
    
    Private Sub txbxDate_Change()
    If IsDate(txbxDate Then
      ThatDate = CDate(txbxDate)
      If ThatDate is in the Valid Range then
        Exit Sub
      Else
        ThatDate = Null
        .txbxDate = ""
        ShowDateWarning
      End If
    Else
      .txbxDate = ""
       ShowDateWarning
    End If
    
    Private Sub ShowDateWarning()
       With lblDateWarning
        'Position over txbxDate
        .top = 123
        .Left = 456
            'lblDateWarning is not visible at run time.
        .Visible = True
      End With
    End Sub
    
    Private Sub lblDateWarning_click()
       lblDateWarning.Visible = False
       txbxDate.SetFocus
    End Sub
    
    Private Sub UpdateDBField()
       Access.SomeDB.SomeDate = Format(ThatDate, "ddmmyy")
    End Sub
    Please note that the above is NOT real code.
    Last edited by SamT; 06-11-2018 at 04:24 PM.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    It would be a lot easier to use an ActivX textbox at least for the input.

    I'm guessing you are using an InputBox??

    See if this does it (only one textbox needed)

    Sub insertdate()
    Dim osld As Slide
    Dim strDate As String
    Set osld = SlideShowWindows(1).View.Slide
    Do
    strDate = InputBox("Enter Date")
    ' TextBox 3 must exist!
    If Not IsDate(strDate) Then osld.Shapes("TextBox 3").TextFrame.TextRange = "Invalid Date"
    Loop While Not IsDate(strDate)
     osld.Shapes("TextBox 3").TextFrame.TextRange = Format(strDate, "dd mmm yy")
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

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