0

--

I badly need your help guys. I'm stuck with these problems for a almost a month . I need to get the time and date if the user tap on the scanner.

Private Sub Command1_Click()
Adodc1.RecordSource = "select * from tbl_login where user = '" + Text1.text + "'"
Adodc1.Refresh

If Adodc1.Recordset.EOF Then
    MsgBox "Login Failed", vbCritical + vbOKOnly, "Error"
Else
    Adodc1.RecordSource = "update tbl_login set dte = '" & Label1.Caption & "' set tme '" & Label2.Caption & "' where user = '" + Text1.text + "'"
    MsgBox "Login Successful!", vbExclamation + vbOKOnly, "Welcome"
    Text1.text = ""
    Text2.text = ""
End If
End Sub


Private Sub Timer1_Timer()
Label1.Caption = Format(Now, "dddd   mmmm dd, yyyy")
Label2.Caption = Format(Now, "hh: mm: ss ampm")
End Sub

It shows the Login Successful, but it doesn't record the time and date of the user. Help please, help me fix this.

2 Answers2

0

Firstly, I would suggest always using the ampersand operator (&) for string concatenation, not the addition operator (+).


Assuming that your fields dte and tme are datetime fields, then the reason that your UPDATE query fails is because you are not providing the date & time data in an appropriate format required for SQL.

However, rather than using concatenation to insert the data into your UPDATE query, I would instead suggest parameterising the query and passing the date, time, and username to the parameters, for example:

With CurrentDb.CreateQueryDef("", "update tbl_login set tbl_login.dte = @dte, tbl_login.tme = @tme where tbl_login.user = @usr")
    .Parameters(0) = Date
    .Parameters(1) = Now
    .Parameters(2) = Text1.Text
    .Execute
End With

You can find out more about parameterised queries from this excellent answer.

Lee Mac
  • 15,615
  • 6
  • 32
  • 80
0

Simply insert date and time:

Adodc1.RecordSource = "update tbl_login set dte = Date(), tme = Time() where user = '" & Text1.text & "'"
Gustav
  • 53,498
  • 7
  • 29
  • 55