In VBA, how to compare date variable with date/time field from table, as when defined the data type in table, date/time option is the only choice for date data type even though I don't want the time portion. MANY Thanks!!
[B]txtScanPart[/B] = "20" & strScanData ' strScanData = "140211234953"
strDate = "#" & Left([txtScanPart], 4) & "-" & _
Mid([txtScanPart], 5, 2) & "-" & _
Mid([txtScanPart], 7, 2) & "#"
strTime = "#" & Mid([txtScanPart], 9, 2) & ":" & _
Mid([txtScanPart], 11, 2) & ":" & _
Right([txtScanPart], 2) & "#"
lngDate = CDate(strDate) ' = "#2014-02-11#"
lngTime = CDate(strTime) ' = "#23:49:53#"
' lngDate = DateValue(strDate)
' lngTime = DateValue(strTime)
' dateBarcode = DateValue(strDate)
' timeBarcode = DateValue(strTime)
' dateBarcode = CDate(strDate)
' timeBarcode = CDate(strTime)
' lngDate = Left([txtScanPart], 8)
' lngTime = Right([txtScanPart], 6)
' dateBarcode = CDate(Format(lngDate, "YYYYMMDD"))
' timeBarcode = CDate(DateValue(lngTime))
[B]txtBarcode[/B] = DateValue(dateBarcode) + _
DateValue(timeBarcode) ' txtBarcode as Longdate textbox
How do you scan the barcode?
Where is it stored?
What does it look like?
Dim strScanByte As String
Dim strDate As String
Dim strTime As String
Dim lngDate As Long
Dim lngTime As Long
Dim dateBarcode As Date
Dim timeBarcode As Date
I don't really see the end goal, but you're certainly making a mistake here:
lngTime = DateValue(strTime)
as you'd want the TimeValue() function to get a time. Thus if all else is working correctly how about:
txtBarcode = DateValue(dateBarcode) + TimeValue(timeBarcode)
Dim txtScanPart As String
Dim dateBarcode As Date
Dim timeBarcode As Date
Dim strDate As String
Dim strTime As String
txtScanPart = "20140211234953" ' strScanData = "140211234953"
strDate = Left([txtScanPart], 4) & "-" & _
Mid([txtScanPart], 5, 2) & "-" & _
Mid([txtScanPart], 7, 2)
strTime = Mid([txtScanPart], 9, 2) & ":" & _
Mid([txtScanPart], 11, 2) & ":" & _
Right([txtScanPart], 2)
dateBarcode = DateValue(strDate)
timeBarcode = TimeValue(strTime)
Debug.Print dateBarcode + timeBarcode
'---------------------------------------------------------------------------------------
' Procedure : Test201402
' Author : Jack
' Date : 19/02/2014
' Purpose : Demo routine to separate a timestamp string into Date and Time where
' Date and Time are Date data types.
'---------------------------------------------------------------------------------------
'
Sub Test201402()
Dim Filename As String
Dim MyDate As Date
Dim MyTime As Date
Filename = "20140211234953"
MyDate = DateSerial(Left(Filename, 4), Mid(Filename, 5, 2), Mid(Filename, 7, 2))
MyTime = TimeSerial(Mid(Filename, 9, 2), Mid(Filename, 11, 2), Mid(Filename, 13, 2))
Debug.Print MyDate & " " & MyTime
End Sub