guys i am having some trouble here, please help me. I need it badly. What happens is when i ckick on the log in button, the button must first verify the date, then the password and username, if the date doesnt exist on the user's database, he should be logged in. But if the date already exist, he must wait for until the next day to log in again. but it is not working properly please help here is my code:

Private Sub Command3_Click()
Dim cnuser As New ADODB.connection
Dim rsuser As New ADODB.recordset
Dim rstimekeeping As New ADODB.recordset
'Dim rsdate As New ADODB.recordset

Call connection(cnuser, App.Path & "\JOCPAY.mdb", "engman")
Call recordset(rsuser, cnuser, "SELECT * FROM UserAccount")

If recfound(rsuser, "emp_id", Text1.Text) = False Then

MsgBox "Invalid Username.", vbExclamation, "JOC Marketing"
   
    Text1.SetFocus
    Call hlfocus(Text1)
Else
        If password = Text2.Text Then
        If rstimekeeping.State = adStateOpen Then rstimekeeping.Close
       rstimekeeping.Open "select * from time_info where date_now = " & FormatDateTime(Now, vbShortDate) & " and emp_id = '" & Text1.Text & "'", cnuser, adOpenStatic, adLockOptimistic
       'rsdate.Open "select * from Paygen", cnuser, adOpenStatic, adLockOptimistic
         'If rstimekeeping("emp_id").Value <> Text1.Text Then
            rstimekeeping.Requery
                With rstimekeeping
                
                 If rstimekeeping("date_now").Value <> FormatDateTime(Now, vbShortDate) Then
                
                        .AddNew
                        .Fields!emp_id = Text1.Text
                        .Fields!time_in = Time
                        .Fields!date_now = Date
                        .Update
                        
                         MsgBox "Successfully logged-in.", vbInformation, "JOC Marketing"
                         
                            
                'rstimekeeping("date_now").Value = Date
                    
                Else
                
                    If rstimekeeping("time_in").Value = "" Then
                    
                        .AddNew
                        .Fields!emp_id = Text1.Text
                        .Fields!time_in = Time
                        .Fields!date_now = Date
                        .Update
                        
                         MsgBox "Successfully logged-in.", vbInformation, "JOC Marketing"
                         
                    Else
                        If rstimekeeping("time_in").Value <> "" Then
                            MsgBox "You have already logged-in", vbExclamation, "JOC Marketing"
                        Else
                            
                        End If
                    End If
                
                End If
                    Call empOper
                End With
              
                Call viewuser
             
        Else
           
            
                MsgBox "Invalid Password.", vbExclamation, "JOC Marketing"
           Call clearLBL
           
        End If
        



            Text1.SetFocus
            Command2.Value = True
            
  
 Call empdLoad
    End If
   
Set cnuser = Nothing
Set rsuser = Nothing
Set rstimekeeping = Nothing
'Set rsdate = Nothing

End Sub

Hi,

What is it not doing properly ?

Denis

Thanks for the new thread, ignore my post on the previous.

It seems that your call to the date is incorrect in your select statement. Try the following - (If you had this in encoded brackets, I could have told you on which line..)

rstimekeeping.Open "select * from time_info where date_now = " & FormatDateTime(Now, vbShortDate) & " and emp_id = '" & Text1.Text & "'", cnuser, adOpenStatic, adLockOptimistic

'Change to...

Dim MyDateNow As Date
MyDateNow = Now

rstimekeeping.Open "SELECT * FROM time_info WHERE date_now = DateValue(" & "'" & MyDateNow & "') AND emp_id = '" & Text1.Text & "'", cnuser, adOpenStatic, adLockOptimistic

If rstimekeeping.BOF = True Or rstimekeeping.EOF = True Then
   'Todays date not in dataset, add ne
 rstimekeeping. AddNew 'and the rest of your code here...
      Else
   'Exit here because the date exists...
End If

Hi Andre i think I know this one..where a sys user cant log in twice in a day or logout twice. I cant make up the whole code right now, I give it to you 2morrow..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.