Home > database >  textBox to Date MS Access
textBox to Date MS Access

Time:12-15

Please have at look on my issue. Background data: ItemB - field with date type, which has YYMMDDHHNN format inptdate - textBox for input data in YYMMDDHHNN format What needed, transform data from String format (inptdate) into Date format(ItemB)

My way

Private Sub Idate_AfterUpdate()

    Dim mydate As String
        mydate = "2212131400"
        inptdate= mydate
        Me.ItemB = CDate(Mid(mydate, 6, 2) & "," & Mid(mydate, 4, 2) & "," & Mid(mydate, 2, 2) & " " & Mid(mydate, 8, 2) & ":" & Mid(mydate, 10, 2))
    
End Sub

but my code execute with an "Type mismatch" error

CodePudding user response:

You can use Format and CDate:

Dim TrueDate As Date

mydate = "2212131400"
TrueDate = CDate("20" & Format(mydate, "@@\/@@\/@@ @@\:@@"))
  • Related