Results 1 to 5 of 5
  1. #1
    rmd62163 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    17

    Dcount for 2 criteria date fields

    Is it possible if what I would like to accomplish is to rule out duplicate value. With a form with two fields one is a date field formatted as short date and the other is a lookup combo box that I use to lookup predefined times and is formatted as short time. The date and time are stored in the same table as date/time in separate fields. I attempted to use Dcount, and get syntax error missing operator. Below is one of a hundred that i have tried after scouring this forum and the net. I ended up converting the Appt_Time field to a text field in the table to eliminate one date field but still got no where. Any suggestions as to the syntax or perhaps a different approach would be greatly appreciated?

    Code:
    Private Sub Appt_Time_BeforeUpdate(Cancel As Integer)
        'Check table for duplicate
    If DCount("[Appt_Time]", "tblexams", "Appt_Time= & Appt_Time &   And [Sch_Date] = #" & Sch_Date & "#") > 0 Then
            'Message box warning of duplication
            'MsgBox "Warning Appointment Time " _
                 & Appt_Time & " has already been assigned" _
                 & vbCr & vbCr & "Please select another Time", _
                   vbInformation, "Duplicate Information"
            'Undo duplicate entry
           Me.Undo
            Cancel = True
        End If
    End Sub


  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Here's what I think about Lookup Fields: http://access.mvps.org/access/lookupfields.htm
    They do not contain what you think they do.

  3. #3
    rmd62163 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    17
    My lookup is pulling the times from one table (tblhours) and storing that in a different table (tblExams). So if I am reading what you are saying correctly that should not pertain to this database. Or am I miss interpreting it? Or are you saying that the lookup comboBox is what's screwing the Dcount?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I believe a Lookup Field is really an array.

  5. #5
    rmd62163 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    17
    Came up with a solution if anyone runs into this type of issue. Made a query.
    Code:
    SELECT tblexams.Appt_Time, tblexams.Sch_Date, tblexams.Patient_ID
    FROM tblexams
    WHERE (((tblexams.Appt_Time)=[Forms]![Patient]![Exams Subform]![Appt_Time]) AND ((tblexams.Sch_Date)=[Forms]![Patient]![Exams Subform]![Sch_Date]) AND (Not (tblexams.Cx) Is Null) AND (Not (tblexams.NS) Is Null) AND (Not (tblexams.RS) Is Null));
    . then I ran
    Code:
    If DCount("*", "qryDupTime") > 0 Then
    on the before update event.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 02-26-2014, 05:06 PM
  2. Most Recent Date Criteria Across Two Fields
    By jaypoppin in forum Queries
    Replies: 5
    Last Post: 06-15-2012, 11:30 AM
  3. DCount with Multiple Criteria
    By Newbie11 in forum Reports
    Replies: 4
    Last Post: 05-25-2012, 09:04 AM
  4. How do you use DCOUNT for multiple criteria?
    By wwhit in forum Programming
    Replies: 5
    Last Post: 05-15-2012, 11:14 AM
  5. Replies: 1
    Last Post: 02-25-2011, 06:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums