Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB6
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.
 
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 12-Apr-13 8:09am
Edited 12-Apr-13 8:13am
CHill6066.9K
v2
Comments
CHill60 at 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 at 12-Apr-13 13:15pm
   
line 11 userLogintime = Rs(0).Value gives the error
CHill60 at 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 at 12-Apr-13 13:26pm
   
worked like a baby! thanks man.
Sergey Alexandrovich Kryukov at 12-Apr-13 13:30pm
   
I hope you understand why did I delete your "answer" which you even accepted formally. Why?
—SA
Aleu Philip at 12-Apr-13 13:32pm
   
I dont..would be pleased to
 
well i do..am not the author..thanks man.
Sergey Alexandrovich Kryukov at 12-Apr-13 15:34pm
   
Sorry for possible miscommunication…
ThePhantomUpvoter at 12-Apr-13 13:28pm
   
You are trying to return a datetime from your function as an integer.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^]
rstEmployees.AddNew
rstEmployees!firstname = strFirstName
rstEmployees!LastName = strLastName
rstEmployees.Update
 
But remember, you need to open Recordset[^] with adLockOptimistic LockType[^].
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 105
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 12 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100