DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4

Thread: Access Form

  1. #1
    Join Date
    Aug 2007
    Posts
    58

    Access Form

    I have created two tables: Employees & TimeClock. I have created a form called ClockIn.

    What I am trying to do is have the form to check if the employeename and password matches what is in the Employees Table. if that matches then the employee is able to clockin. When the employee clocks in, the data is sent to the TimeClock Table. Once the Employees Table has been checked, the data matched, then the form determines if today matches any value in the TimeClock table with the employeename. If it does not match, then a new row is suppose to be created.

    As of right now, a new record is not created. The row containing the employeename is just updated.

    Here is the code I have so far:

    Code:
    Option Explicit
    Option Compare Database
    Private intLogonAttempts As Integer
    Public MyEmpName As String
    
    Private Sub Form_Open(Cancel As Integer)
    'On open set focus to combo box
    Me.txtEmployeename.SetFocus
    Me.txtEmployeename.Value = ""
    Me.txtClockInDate.Value = Format(Now, "mmm d yyyy")
    intLogonAttempts = 0
    End Sub
    
    Private Sub Form_Timer()
        Me!lblClock.Caption = Format(Now, "dddd, mmm d yyyy, hh:mm:ss AMPM")
    End Sub
    
    Private Sub txtEmployeeName_AfterUpdate()
    'After selecting user name set focus to password field
    Me.txtPassword.SetFocus
    End Sub
    
    Private Sub cmdClockIn_Click()
    
    Dim blnFound As Boolean
    
    blnFound = False
    
        'Check to see if data is entered into the UserName Textbox
    
        If IsNull(Me.txtEmployeename) Or Me.txtEmployeename = "" Then
                MsgBox "Employee Name is a required field.", vbOKOnly, "Required Data"
                Me.txtEmployeename.SetFocus
            Exit Sub
        End If
    
        'Check to see if data is entered into the password box
    
        If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
                MsgBox "Password is a required field.", vbOKOnly, "Required Data"
                Me.txtPassword.SetFocus
            Exit Sub
        End If
    
        'Check value of password in Employees to see if this matches value entered into textbox
    
        If Me.txtPassword = DLookup("Password", "Employees", "EmployeeName='" & Me.txtEmployeename.Value & "'") Then
    
            MyEmpName = Me.txtEmployeename.Value
            
            'blnFound = True
            
         Else
         
            MsgBox "Employee Name or Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
            Me.txtEmployeename.SetFocus
            Me.txtEmployeename = ""
            Me.txtPassword = ""
            
            Exit Sub
            
        End If
        
    'If User Enters incorrect password 3 times database will shutdown
        
        intLogonAttempts = intLogonAttempts + 1
        If intLogonAttempts = 3 Then
            MsgBox "You do not have access to this database.  Please contact your system administrator.", vbCritical, "Access is Denied!"
            Application.Quit
        End If
        
        Dim fldItem As ADODB.Field
        Dim fldItem2 As ADODB.Field
        Dim rstTimeClock As ADODB.Recordset
        Dim strDate As String
        
        'Me.txtClockIn.Value = Format(Now, "dddd, mmm d yyyy")
        
        Set rstTimeClock = New ADODB.Recordset
        rstTimeClock.Open _
            "SELECT * FROM TimeClock WHERE EmployeeName = '" & _
                txtEmployeename & "'", _
                    CurrentProject.Connection, _
                        adOpenStatic, adLockReadOnly, adCmdText
        
    With rstTimeClock
        'Check each record
        While Not .EOF
            'Check the name of the column
            For Each fldItem In .Fields
                'if the current column is Password
                If fldItem.Name = "ClockIn" Then
                    'Check the value
                    'If the current column holds the same employee password
                    'the employee entered
                    If fldItem.Value <> Me.txtClockInDate.Value Then
                        '... then get the record and display
                        'the full name in the controls
                        'Me.txtEmployeeName = .Fields("EmployeeName")
                        '.Fields("EmployeeName") = Me.txtEmployeeName.Value
                        
                        blnFound = True
                    
                    Else
                    
                        MsgBox "You have all ready clocked in today."
                        
                    End If
                End If
            Next
            'In case it was not found, move to the next record
            .MoveNext
        Wend
    End With
        
        If blnFound = True Then
            On Error GoTo Err_cmdClockIn_Click
        
        DoCmd.GoToRecord , , acNewRec
        
    
    Exit_cmdClockIn_Click:
        Exit Sub
    
    Err_cmdClockIn_Click:
        MsgBox Err.Description
        Resume Exit_cmdClockIn_Click
        
    End If
    
    Application.Quit
    
    End Sub

  2. #2
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    can you just highlight where you have a problem to make it easier ? most of ppl doesn't have time to look inside all this codeing .
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    Try putting a break on the routine and stepping through it to see what is actually happening when it runs.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  4. #4
    Join Date
    Nov 2007
    Posts
    4
    1) I would think that adLockReadOnly might mean exactly what it says: read only (can't add records). As written, this is a moot point because...

    2)
    >DoCmd.GoToRecord , , acNewRec
    This would be used to move a *bound form* to a new record, not for movement within a recordset.
    You are trying to add a record to the Form's recordset and, afaik, the form doesn't have a recordset to add to.
    If you want to add a record to the Recordset you opened in code, you want something like:
    Code:
    rstTimeClock.AddNew
    rstTimeClock!EmployeeName = MyEmpName
    '   (Add Date, Time and other data to record..)
    rstTimeClock.Update
    3) You want to at least change your loop so that a) you actually exit the loop if a match is found b) avoid looping through fields names (!!!) and c) set & test blnFound properly:
    Code:
    While Not .EOF And Not blnFound
    If clng(!ClockIn) <> cdate(Me.txtClockInDate.Value) Then
    'No match, keep looking
    Else
    'Match found blnFound = True
    End If .MoveNext
    Wend[/INDENT] If blnFound = False
    'Add record
    Else
    MsgBox "You have already logged in today."
    End If
    Alternatively you could skip the recordset entirely:
    Code:
    strResult = nz(Dlookup("empname","TimeClock", EmpMatch? AND DateMatch?),"")
    if strResult = "" Then
    'No Emp & Date match. ' Add record with INSERT INTO
    else
    'Display message
    end if
    Last edited by GeorgeN; 11-29-2007 at 02:41 PM.

Similar Threads

  1. Replies: 6
    Last Post: 10-01-2009, 05:42 AM
  2. microsoft access - loading a form
    By svn in forum Database
    Replies: 1
    Last Post: 06-26-2006, 04:13 PM
  3. MS access form
    By obinna eleanya in forum VB Classic
    Replies: 1
    Last Post: 09-01-2005, 11:45 AM
  4. Access OCX code without using a form
    By Peter Merwood in forum VB Classic
    Replies: 2
    Last Post: 03-01-2002, 02:42 PM
  5. Open Access database Form from VB 6.0?
    By Demo in forum VB Classic
    Replies: 7
    Last Post: 07-25-2000, 08:10 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links