date / time field problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I have a table which contains a field of type date/time.
for various reasons i have a form (unbound) and code behind needs to add a
record into table using values in unbound txt boxes. i get type mismatch
error as i have tried Dim the variable which contains the contents of the
unbound txt box as both string and tried date. there is not 'time' format.
How do i get this txt into the field. the contents of the txt box are for
example '01:15:35' ie 1hr 15mins and 35 secs.
Many Thanks
David
 
. i get type mismatch
error as i have tried Dim the variable which contains the contents of
the unbound txt box as both string and tried date.

Any variable that receives the contents of a text box really needs to be
a Variant, because an empty text box returns Null.
there is not 'time' format. How do i get this txt into the field.

You don't want a format, which converts from value to text; you need a
CDate function

varMyBox = myTextBox.Value
If IsNull(varMyBox) Then
' empty is allowed?
Cancel = False

ElseIf Not IsDate(varMyBox) Then
' rubbish not allowed here
MsgBox varMyBox & " is a load of rubbish, try again"
Cancel = True

ElseIf DateValue(varMyBox) > 0 Then
' it's a date not a time
MsbBox varMyBox & " looks like a date, try again"
Cancel = True

ElseIf TimeValue(varMyBox) = 0 Then
' strange kind of rubbish, no time value passed
MsgBox varMyBox & " doesn't have any time, try again"
Cancel = True

Else
' hooray, validation passed
Cancel = False

rst.MyDateField = CDate(varMyBox)

End If


Hope that helps



Tim F
 
Back
Top