Page 1 of 4 1234 LastLast
Results 1 to 15 of 52
  1. #1
    islandboy is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2009
    Posts
    63

    If duplicate record, go to original record

    hello guys, i am new to this site and new to access.

    i am using Access 2007 to create a DB for my IGCSE project.

    i wanted to create a msg box if a user enter a duplicate data.

    but now even if i enter diff data it still says that the number is being used.

    here is the code..by the way this code won't take me to the to the record even if i enter a used number.



    Thanks.

    Private Sub PostNumber_BeforeUpdate(Cancel As Integer)

    Dim SID As String
    Dim stLinkCriteria As String
    Dim rsc As DAO.Recordset

    Set rsc = Me.RecordsetClone

    SID = Me.[Post Number].Value
    stLinkCriteria = "[PostNumber]=" & "'" & SID & "'"

    'Check Employee Table table for duplicate
    If DCount("PostNumber", "Employee Table", stLinkCriteria) > 0 Then
    'Undo duplicate entry
    Me.Undo 'Undo this entry.
    'Message box warning of duplication
    MsgBox "Warning Post Number " _
    & SID & " has already been entered." _
    & vbCr & vbCr & "You will now been taken to the record.", _
    vbInformation, "Duplicate Information"
    'Go to record of original record
    'rsc.FindFirst stLinkCriteria
    'Me.Bookmark = rsc.Bookmark

    End If

    Set rsc = Nothing

    End Sub

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    If you want to go to the previous record for the entry then use the AfterUpdate event rather than the BeforeUpdate event of the control.

  3. #3
    islandboy is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2009
    Posts
    63
    Quote Originally Posted by RuralGuy View Post
    If you want to go to the previous record for the entry then use the AfterUpdate event rather than the BeforeUpdate event of the control.

    hey mate,

    am new to access can you tell me how to change it?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Move the code you have to the AfterUpdate event of the same control and un-comment the lines and give it a try.

  5. #5
    islandboy is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2009
    Posts
    63
    Quote Originally Posted by RuralGuy View Post
    Move the code you have to the AfterUpdate event of the same control and un-comment the lines and give it a try.

    sorry but can u be more specific if u dnt mind?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Can you move the code in the BeforeUpdate event to the AfterUpdate event?

  7. #7
    islandboy is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2009
    Posts
    63
    Quote Originally Posted by RuralGuy View Post
    Can you move the code in the BeforeUpdate event to the AfterUpdate event?

    ok in the m on the properth sheet and i see the event....

    you mean copy the code and change to the AfterupDate?

    what i need to change in the code so it can work?

  8. #8
    islandboy is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2009
    Posts
    63
    Quote Originally Posted by islandboy View Post
    ok in the m on the properth sheet and i see the event....

    you mean copy the code and change to the AfterupDate?

    what i need to change in the code so it can work?

    i get this error when i do that.

    Private Sub PostNumber_AfterUpdate()

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    In solving this problem how about telling us what an IGCSE project is? Do you have an error message? Maybe an error Number? Post what you have starting with Private and ending with End Sub.

  10. #10
    islandboy is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2009
    Posts
    63
    Quote Originally Posted by RuralGuy View Post
    In solving this problem how about telling us what an IGCSE project is? Do you have an error message? Maybe an error Number? Post what you have starting with Private and ending with End Sub.


    the project is one the i choose to make about HR.


    Private Sub PostNumber_AfterUpdate()

    Dim SID As String
    Dim stLinkCriteria As String
    Dim rsc As DAO.Recordset

    Set rsc = Me.RecordsetClone

    SID = Me.PostNumber.Value
    stLinkCriteria = "[PostNumber]=" & "'" & SID & "'"

    'Check Employee Table table for duplicate
    If DCount("PostNumber", "Employee Table", stLinkCriteria) > 0 Then
    'Undo duplicate entry
    Me.Undo
    'Message box warning of duplication
    MsgBox "Warning Post Number " _
    & SID & " has already been entered." _
    & vbCr & vbCr & "You will now been taken to the record.", _
    vbInformation, "Duplicate Information"
    'Go to record of original record
    'rsc.FindFirst stLinkCriteria
    'Me.Bookmark = rsc.Bookmark

    End If

    Set rsc = Nothing
    End Sub



    even with this code i still get the box that says "Dublicate Information" Warning Post Number 11 has already been entered. You Will now been taken to the record.

    but the record 11 isn't there i am sure of that..

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    What does IGCSE mean?

  12. #12
    islandboy is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2009
    Posts
    63

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is the [PostNumber] field a NUMERIC or TEXT field?

  14. #14
    islandboy is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2009
    Posts
    63
    Quote Originally Posted by RuralGuy View Post
    Is the [PostNumber] field a NUMERIC or TEXT field?

    Numeric (Number) my friend

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    So you do not want the single quotes:
    Code:
    Private Sub PostNumber_AfterUpdate()
       Dim SID As String
       Dim stLinkCriteria As String
       Dim rsc As DAO.Recordset
       Set rsc = Me.RecordsetClone
       SID = Me.PostNumber
       stLinkCriteria = "[PostNumber]=" & SID
       'Check Employee Table table for duplicate
       If DCount("PostNumber", "Employee Table", stLinkCriteria) > 0 Then
          'Undo duplicate entry
          Me.Undo
          'Message box warning of duplication
          MsgBox "Warning Post Number " _
                 & SID & " has already been entered." _
                 & vbCr & vbCr & "You will now been taken to the record.", _
                 vbInformation, "Duplicate Information"
          'Go to record of original record
          rsc.FindFirst stLinkCriteria
          Me.Bookmark = rsc.Bookmark
       End If
       Set rsc = Nothing
       
    End Sub

Page 1 of 4 1234 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. If duplicate record, go to original record
    By BigBear in forum Forms
    Replies: 2
    Last Post: 10-06-2010, 02:58 AM
  2. Duplicate record failure
    By bugchaser in forum Access
    Replies: 5
    Last Post: 05-21-2009, 08:38 AM
  3. Replies: 0
    Last Post: 01-06-2009, 02:17 PM
  4. Deleting Record Contents, not complete record...
    By Charles Waters in forum Access
    Replies: 2
    Last Post: 06-24-2008, 12:00 PM
  5. i need record dividers
    By dunston in forum Reports
    Replies: 1
    Last Post: 11-11-2006, 07:57 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