Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Stop data entry if certain criteria exists

Posted on 2014-04-28
1
Medium Priority
?
325 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

972 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