Now() type mismatch

judgebeddie
judgebeddie used Ask the Experts™
on
I always get a type mismatch error when comparing the current time Now() to a date/time field. I want to have the text box border flash when the current time has passes the "Alarm" time. I can't even get the current time to be copied into a date/time field for testing.

Sample code:
Private Sub test_button_Click()
    Let Now() = Me.CDAsAlarm
    If Now() > Me.CDAsAlarm Then  
        With Me.CDAsTime
            .BorderColor = (IIf(.BorderColor = vbBlue, vbRed, vbBlue))
        End With
    End If    
End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Try this instead:
Sample code:
Private Sub test_button_Click()
    Let Now() = "#" & Me.CDAsAlarm & "#"
    If Now() > "#" & Me.CDAsAlarm & "#" Then  
        With Me.CDAsTime
            .BorderColor = (IIf(.BorderColor = vbBlue, vbRed, vbBlue))
        End With
    End If    
End Sub

Open in new window


HTH,
Daniel
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007
Commented:
It's kind of backwards

Let Now() = Me.CDAsAlarm

>>

Me.CDAsAlarm = Now()

You can't set Now() to something ... it is what it is.

mx
Database Architect / Application Developer
Top Expert 2007
Commented:
Not quite sure what you are trying to do, but start with this:

    Me.CDAsAlarm = Now()
    If Me.CDAsAlarm > Now() Then
        With Me.CDAsTime
            .BorderColor = (IIf(.BorderColor = vbBlue, vbRed, vbBlue))
        End With
    End If

mx

Author

Commented:
I was abel to use MX solution; but Daniel gave good pointers...thanks! I still have to work out a timing issue, but thats a different problem.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial