error 94: invalid use of Null

emsadoon

Registered User.
Local time
Today, 10:50
Joined
Jun 6, 2013
Messages
83
Hi, Can anyone please let me knowhow to resolve error 94 in the following code:

Code:
Private Sub Form_Current()
Dim strTime As String
Dim strHour As String
Dim strMinute As String
If (CollectionTime.Value) = "" Then
MsgBox CollectionTime
Me.Hour = ""
Me.Minute = ""
Else
strTime = Me.CollectionTime
Dim intcolon As Integer
intcolon = InStr(strTime, ":")
strHour = Left$(strTime, intcolon - 1)
strMinute = Right$(strTime, Len(strTime) - intcolon)
Me.Hour = strHour
Me.Minute = strMinute
End If

End Sub
 
Just going to guess. The Me.Hour Me.Minute use reserved words.

Once I named some textboxs First, Second, Third...
Spent hours chasing my tail.
Second is a reserved word (for type time).

First try to get rid of any reserved words.

If in question, to to code module, press the F2 and search.
The Object Browser is your best friend in programming.
 
First try to get rid of any reserved words.
Agreed, do this and you can use the Hour and Minute functions.

You may also need to test CollectionTime for NULL using the nz() function.

Code:
Private Sub Form_Current()
    Dim strCollectionTime As String
    strCollectionTime = Nz(Me.CollectionTime, "")
    If strCollectionTime = "" Then
        Me.CollectionHour = ""
        Me.CollectionMinute = ""
    Else
        Me.CollectionHour = Hour(strCollectionTime)
        Me.CollectionMinute = Minute(strCollectionTime)
    End If
End Sub
 
Thanks, you are right. I made it work by just removing
Code:
MsgBox CollectionTime
, because I had null value for CollectionTime, therefore the MsgBox was causing this error.
 
Thanks for the feedback! That is good to know.
Be sure and mark your original post as Solved
 

Users who are viewing this thread

Back
Top Bottom