How to Update one of the table's field with current time

B

benedict.cardoza

Hi,

I am into a grave problem which might be simple, But i cant do it
So, pleaze can any one help me,
Wud b Greatful...

Here goes the Problem........

I have a table with three fileds username, timein, timeout
Now what i have to do is, I have created a VB(its VB6 not VB.NEt) form
where in i am taking in Username from the user and inserting th
current time for that very moment.

Now as soon as user log's out i want to update his Timeout filed wit
the current time.
I am doin the following ...

Private Sub Form_Load()
EnableCloseButton Me.hWnd, False
Dim con As New ADODB.Connection
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DAT
SOURCE=D:\Bonny\db1.mdb"
con.Open
mysql = "Update tabUser set timeout='TimeValue(now())' wher
username='usernamepass'"
con.Execute(mysql)
con.Close
End Sub

(Where Usernamepass is the username i am taking on my first form o
login, and passing it to this form)

Regards..
Bonn
 
D

David Lloyd

Bonny:

You need to remove the single quotes from around the TimeValue statement,
otherwise it will generate a type mismatch for a Date/Time field. For
example:

mysql = "Update tabUser set timeout=TimeValue(now()) where
username='usernamepass'"

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


"benedict.cardoza" <[email protected]>
wrote in message

Hi,

I am into a grave problem which might be simple, But i cant do it
So, pleaze can any one help me,
Wud b Greatful...

Here goes the Problem........

I have a table with three fileds username, timein, timeout
Now what i have to do is, I have created a VB(its VB6 not VB.NEt) form
where in i am taking in Username from the user and inserting the
current time for that very moment.

Now as soon as user log's out i want to update his Timeout filed with
the current time.
I am doin the following ...

Private Sub Form_Load()
EnableCloseButton Me.hWnd, False
Dim con As New ADODB.Connection
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
SOURCE=D:\Bonny\db1.mdb"
con.Open
mysql = "Update tabUser set timeout='TimeValue(now())' where
username='usernamepass'"
con.Execute(mysql)
con.Close
End Sub

(Where Usernamepass is the username i am taking on my first form of
login, and passing it to this form)

Regards..
Bonny
 
D

Douglas J. Steele

mysql = "Update tabUser set timeout=" & _
Format(Time(), "\#hh\:nn\:\ss\#") & _
" where username='usernamepass'"
 
R

Rick Brandt

benedict.cardoza said:
Hi,

I am into a grave problem which might be simple, But i cant do it
So, pleaze can any one help me,
Wud b Greatful...

Here goes the Problem........

I have a table with three fileds username, timein, timeout
Now what i have to do is, I have created a VB(its VB6 not VB.NEt) form
where in i am taking in Username from the user and inserting the
current time for that very moment.

Now as soon as user log's out i want to update his Timeout filed with
the current time.
I am doin the following ...

Private Sub Form_Load()
EnableCloseButton Me.hWnd, False
Dim con As New ADODB.Connection
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
SOURCE=D:\Bonny\db1.mdb"
con.Open
mysql = "Update tabUser set timeout='TimeValue(now())' where
username='usernamepass'"
con.Execute(mysql)
con.Close
End Sub

(Where Usernamepass is the username i am taking on my first form of
login, and passing it to this form)

Regards..
Bonny

You've indicated what you want to do, but not what the problem is. Do you get
an error? Do you get no error but no update? Do you get an incorrect update or
an update to the wrong record?

Off hand I'd guess that you should not have single quotes around the
TimeValue(now()) portion of the SQL.
 
J

John Spencer

A Guess. Try Changing the SQL statement to hold the actual values vice
references to themn

mysql = "Update tabUser set timeout='" & TimeValue(now()) & _
"' where username='" & usernamepass & "'"

You may have to use the # delimiter around the time vice the ' delimiter.
 
Top