Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Stop data entry if certain criteria exists

Posted on 2014-04-28
1
Medium Priority
?
324 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

705 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