Code Help Please

crann

Registered User.
Local time
Today, 01:10
Joined
Nov 23, 2002
Messages
160
Hi
Firstly Im a complete beginner

I have a table called "tblWorker" which contains my login information:

Code:
WorkerID    |    WorkerName    |    LoginID    |    Password    |    UserType
------------+------------------+---------------+----------------+-----------
12          |    Jonathan      |    jon        |    *****       |    Admin
16          |    donna         |    donna      |    ***         |    User
The login all works fine (I downloaded it), I want to add a timed pop up reminder for tasks that appear in my query "qryTaskDue"

I gratefully downloaded the example and changed the field names to suit mine but when the pop up appears it says:
Invalid use of null.
User = DLookup("WorkerName", "tblWorker", "LoginID = '" & Login & "'")

Im a complete beginner so was hoping someone could look at this code for me please:

Code:
Private Sub Form_Timer()
    Static count As Integer
    count = count + 1
    If count = 30 Then
        Me.TimerInterval = 0
        Call YouHaveTaskDue
        Exit Sub
    End If
End Sub
    
[COLOR=Green]'.......................................................................................[/COLOR]
Sub YouHaveTaskDue()
    Dim Login As String
    Dim User As Integer

    Login = Environ("WorkerName")
    User = DLookup("WorkerName", "tblWorker", "LoginID = '" & Login & "'")
    
    If IsNull(DLookup("taskid", "qryTaskDue", "WorkerName = " & User)) Then
        [COLOR=Green]'do nothing[/COLOR]
    Else
        MsgBox "You have a task due", vbInformation, "TaskDue Alert!"
    End If
End Sub
 
Last edited by a moderator:
Code:
Environ("Workername")
will only work if you if a windows environment variable set for that. if not it will return a null value.

If you are trying to get the users login name using environ it is usually
Code:
Envrion("Username")
.
 
The reason for your error is because of the fact you are using a Dlookup to an Integer. DLookup can return a Null value, which is not compatible with any Data Type other than Variant. So you have to make use of a Nz() function.

Other than that, your code could be simplified by using just one DLookup, why not edit your Query (qryTaskDue) to base on the WorkerName? Instead of User?
Code:
Private Sub Form_Timer()
    Static count As Integer
    count = count + 1
    If count = 30 Then
        Me.TimerInterval = 0
        Call YouHaveTaskDue
        Exit Sub
    End If
End Sub
    
'.......................................................................................
Sub YouHaveTaskDue()
    Dim Login As String
    Dim User As Integer

    Login = Environ("WorkerName")
    User = Nz(DLookup("WorkerName", "tblWorker", "LoginID = '" & Login & "'"), 0)
    
    If IsNull(DLookup("taskid", "qryTaskDue", "WorkerName = " & User)) Then
        'do nothing
    Else
        MsgBox "You have a task due", vbInformation, "TaskDue Alert!"
    End If
End Sub
Also I would use DCount over DLookup in the If condition.
 

Users who are viewing this thread

Back
Top Bottom