Solved

Stop data entry if certain criteria exists

Posted on 2014-04-28
1
313 Views
Last Modified: 2014-04-28
I have a time reporting database that has a form with a start and stop time.

When the employee selects their name from a combo box and if they haven't entered a stop time in their previous transaction I have a message box appearing.  But the problem is, the message box is appearing for any employee even if they don't have "un-ended" transactions.

Here is my code.  Can someone spot the problem for me?

    If IsNull(DMax("[StopTime]", "tblLaborTranx", "[EmployeeID] = " & Forms!frmEmployeeLaborTranx!txtEmployeeID)) Then
        MsgBox "You have not logged out of your last labor transaction. Please be sure to log out of it or see the front office for editing."
        DoCmd.Close acForm, "frmEmployeeLaborTranx", acSaveNo
        Exit Sub
    End If

I also have tried:

    If DMax("[StopTime]", "tblLaborTranx", "[EmployeeID] = " & Forms!frmEmployeeLaborTranx!txtEmployeeID) = "" Then
        MsgBox "You have not logged out of your last labor transaction. Please be sure to log out of it or see the front office for editing."
        DoCmd.Close acForm, "frmEmployeeLaborTranx", acSaveNo
        Exit Sub
    End If

But that doesn't work either.

--Steve
0
Comment
Question by:SteveL13
1 Comment
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 40027338
Your DMAX statement just gets the record with the maximum value in StopTime for a specific employee, so it will almost always return a record (at least I'd think).

Instead, you want to determine if a user has not "logged out" of their last activity? If so, how do you determine when the user has logged out - for example, if I look at the table, how would I know that user has logged out of a specific transaction?

Do you store the "Activity" Stop and Start time in the same record? If so, you could look for any record with a NULL or Empty value in Stop:

Dim rst As DAO.Recordset
Set rst = Currentdb.OpenRecordset("SELECT * FROM tblLaborTranx WHERE (StopTime IS NULL OR StopTime=0) And EmployeeID=" & Forms!frmEmployeeLaborTranx!txtEmployeeID)

If Not (rst.EOF and rst.BOF) Then
  '/ one or more entries do not have a Stop time
  Msgbox "blah blah"
End If

Open in new window


I'm not sure of the datatype for StopTime, so you may need to check it differently.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now