Results 1 to 10 of 10
  1. #1
    vickan240sx is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    34

    Date/Time field, prevent duplicates - Runtime error 3075

    Hi,

    I'm sorry, the error that I'm getting is a run-time error 3464.

    I have the following code to prevent duplicate dates. If the date is a duplicate, it'll bring up a warning message and take me to the record that already exists.

    Code:
    Private Sub TodaysDate_BeforeUpdate(Cancel As Integer)
    
        Dim SID As String
        Dim stLinkCriteria As String
        Dim rsc As DAO.Recordset
    
        Set rsc = Me.RecordsetClone
    
        SID = Me.TodaysDate.Value
        stLinkCriteria = "[TodaysDate]= #" & "'" & SID & "'"
    
        'Check InsuranceNoticesLog table for duplicate TodaysDate
        If DCount("TodaysDate", "InsuranceNoticesLog", _
                  stLinkCriteria) > 0 Then
            'Undo duplicate entry
            Me.Undo
            'Message box warning of duplication
            MsgBox "WARNING: " _
                 & SID & " has already been entered." _
                 & vbCr & vbCr & "You will now been taken to that record.", _
                   vbInformation, "Duplicate Information"
            'Go to record of original Access Bar Code
            rsc.FindFirst stLinkCriteria
            Me.Bookmark = rsc.Bookmark
        End If
    
        Set rsc = Nothing
        
    End Sub
    However, the data type in the table is set to date/time because I want the field in the form to show a calendar and prevent users from inputting an incorrect date format.

    When I changed the data type to text, the code above works. However, when I change the data type to date/time, it no longer works. I know it has something to deal with using an # or something, but I couldn't look up any sample information online.



    Please help.

    Thank you very much.

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    Dates usually need to be surrounded with # signs when referred to in a criteria in a query. You might want to try and add a # sign at the end of your stLinkCriteria.

    BTW--you should not double post your threads in a forum. Once is sufficient to get a proper response. Send a report to the mods asking them to lock or delete the other thread.

  3. #3
    vickan240sx is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    34
    Figured it out!

    Code:
    SID = Me.TodaysDate.Value
        stLinkCriteria = "[TodaysDate]= #" & SID & "#"

  4. #4
    vickan240sx is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    34
    Quote Originally Posted by alansidman View Post
    Dates usually need to be surrounded with # signs when referred to in a criteria in a query. You might want to try and add a # sign at the end of your stLinkCriteria.

    BTW--you should not double post your threads in a forum. Once is sufficient to get a proper response. Send a report to the mods asking them to lock or delete the other thread.
    Oh...I didn't realize that the thread was double posted. After I posted it, I realized that I entered a mistake into my subject and did an edit to my original post. Not sure how it double posted.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Quote Originally Posted by alansidman View Post
    BTW--you should not double post your threads in a forum. Once is sufficient to get a proper response. Send a report to the mods asking them to lock or delete the other thread.
    Duplicate deleted.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    vickan240sx is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    34
    Quote Originally Posted by pbaldy View Post
    Duplicate deleted.
    My apologies. Thank you.

  7. #7
    vickan240sx is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    34
    How do I mark my thread as solved?

  8. #8
    vickan240sx is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    34
    A side question in regards to the same topic.

    When I input data into the date field, then delete that data and try to continue on to another field, I get an error Run-time error '94', invalid use of Null. Is there anyway to get around this?

    I feel that my staff my sometimes enter in data into the date field, but then delete it.

    Thank you for your help.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Quote Originally Posted by vickan240sx View Post
    My apologies. Thank you.
    No apology needed; sounds like the forum did it to you.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    To mark your thread as solved, click on the thread tools at the top of the original posting.

    Is the date field a required field?

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

Similar Threads

  1. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  2. Replies: 5
    Last Post: 03-27-2012, 01:40 PM
  3. RunTime Error 3075, code for search button
    By jacie in forum Programming
    Replies: 1
    Last Post: 04-15-2011, 05:23 AM
  4. Runtime 3075 error
    By whm1 in forum Programming
    Replies: 4
    Last Post: 03-24-2010, 02:50 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