Data Type mismatch in criteria expression

mykil

My Life is Boring
Local time
Tomorrow, 02:48
Joined
Aug 16, 2011
Messages
117
Hi Everyone.

I have a Database for Logging students every time they want to use the Computer Laboratory that works perfectly fine. I have a StudentForm where I input all the students data and a LoginForm where I add them whenever they used the Computer Laboratory that is by entering their IDnumber and then it will automatically supply the student's Info using the Dlookup Codes.

I want to change the ID number format from:

Sample ID Number:

2017-001 to 2017-0000001

So after changing the ID number format it shows this error:
Run-time error '3464'
Data Type mismatch in criteria expression

The code below doesn't work with the New ID number format.
Code:
Private Sub FillUnboundedTextBoxes(IDStud)
    Me.txtLastName = DLookup("[LastName]", "tblStudents", "StudentID=" & IDStud)
Anyone who knows how to fix this problem?

I would really appreciate your help.

If you want to know more please let me know.

Thanks a lot.

:banghead::banghead::banghead:
 
Last edited:
Try

DLookup("[LastName]", "tblStudents", "StudentID='" & IDStud & "'")
 
Try

DLookup("[LastName]", "tblStudents", "StudentID='" & IDStud & "'")

You just saved my day. Thanks a lot.

Another thing:

Is there something wrong with this code:


Code:
 LoginsThisWeek = DCount("StudentID", "tblLogins", WhereClause)
 
That depends what the variable WhereClause is being set to.
 
That depends what the variable WhereClause is being set to.

The purpose of this code is for the user to know how many times he/she loggedIN in the Computer Laboratory every week. This code works fine before I changed the ID number Format.

Code:
Dim StartDate As Date, TotalLogins As Long, LoginsThisWeek As Long
    StartDate = VBA.DateTime.Date
    Do Until Weekday(StartDate) = vbMonday
        StartDate = DateAdd("d", -1, StartDate)
    Loop
    TotalLogins = DCount("StudentID", "tblStudents", "StudentID='" & Me.StudentID & "'")
Dim WhereClause As String
[COLOR=Red] [COLOR=Black]   WhereClause = "[LoginDate] >= " & EnglishDate(StartDate) & " AND StudentID = " & Me.StudentID[/COLOR][/COLOR]
[COLOR=Red]    LoginsThisWeek = DCount("StudentID", "tblLogins", WhereClause)[/COLOR]
 
I think you've to surround the Me.StudentID with ' as you've in the above line.
Code:
TotalLogins = DCount("StudentID", "tblStudents", "StudentID=[B][COLOR=Blue]'"[/COLOR] [/B]& Me.StudentID [B][COLOR=Blue]& "'"[/COLOR][/B]) 
Dim WhereClause As String [COLOR=Red] [COLOR=Black]   
WhereClause = "[LoginDate] >= " & EnglishDate(StartDate) & " AND StudentID = [B][COLOR=Red]'[/COLOR][/B]" & Me.StudentID[/COLOR][/COLOR] & [B][COLOR=Red]"'"[/COLOR][/B]
 
I think you've to surround the Me.StudentID with ' as you've in the above line.
Code:
TotalLogins = DCount("StudentID", "tblStudents", "StudentID=[B][COLOR=Blue]'"[/COLOR] [/B]& Me.StudentID [B][COLOR=Blue]& "'"[/COLOR][/B]) 
Dim WhereClause As String [COLOR=Red] [COLOR=Black]   
WhereClause = "[LoginDate] >= " & EnglishDate(StartDate) & " AND StudentID = [B][COLOR=Red]'[/COLOR][/B]" & Me.StudentID[/COLOR][/COLOR] & [B][COLOR=Red]"'"[/COLOR][/B]

Thanks Much.
 

Users who are viewing this thread

Back
Top Bottom