Solved

Stop data entry if certain criteria exists

Posted on 2014-04-28
1
318 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

685 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