Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Ii've got a funtion UserLoginTime as below. The structure of my userlog table datatype varchar(50) for Username field and datatype datetime for Logintime field. Problem is the following line of code gives me an error at runtime "run-time error '13'. Type mismatch, " Any help where the problem could be. Am not very savvy in vb.

VB
Function UserLoginTime(Username As String, LoginTime As Date) As Integer
If Rs.State = adStateOpen Then Rs.Close
    sql = " Select * From Userlog"
   Rs.Open sql, RSconn
    With Rs
        .AddNew
        !Username = Username
        !LoginTime = LoginTime
        .Update
   End With
   UserLoginTime = Rs(0).Value
Posted
Updated 12-Apr-13 7:13am
v2
Comments
CHill60 12-Apr-13 13:13pm    
When you step through the code with the debugger which line is it precisely that is giving you the error?
Aleu Philip 12-Apr-13 13:15pm    
line 11 userLogintime = Rs(0).Value gives the error
CHill60 12-Apr-13 13:20pm    
Ok .. you've used Select * From Userlog. Try explicitly naming the columns you want returned instead of using "*" - obviously with the LoginTime as the first column :-)
Aleu Philip 12-Apr-13 13:26pm    
worked like a baby! thanks man.
Sergey Alexandrovich Kryukov 12-Apr-13 13:30pm    
I hope you understand why did I delete your "answer" which you even accepted formally. Why?
—SA

1 solution

You can't insert into Recordset until, you add new record!!!

See this: http://msdn.microsoft.com/en-us/library/windows/desktop/ms680885%28v=vs.85%29.aspx[^]
VB
rstEmployees.AddNew
rstEmployees!firstname = strFirstName
rstEmployees!LastName = strLastName
rstEmployees.Update


But remember, you need to open Recordset[^] with adLockOptimistic LockType[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900