Results 1 to 11 of 11
  1. #1
    emilyrogers is offline Advanced Beginner
    Windows 98/ME Access 2003
    Join Date
    Oct 2010
    Posts
    46

    Exclamation Runtime error in preventing duplicates code

    I have this code(below) and when i try and activate it it come up with runtime error- 3021 no current record and when i debug it highlights Me.Bookmark = rsc.Bookmark and i don't know what to do because i am very new to access. Please tell me in very simple terms. The code works until i use it in the switchboard and then the error appears.

    Private Sub Document_ID_BeforeUpdate(Cancel As Integer)


    Dim SID As String
    Dim stLinkCriteria As String


    Dim rsc As DAO.Recordset
    Set rsc = Me.RecordsetClone
    SID = Me.[Document ID].Value
    stLinkCriteria = "[Document ID]=" & "'" & SID & "'"
    'Check [ECNs Pending] table for duplicate [Document ID]
    If DCount("[Document ID]", "[ECNs Pending]", _
    stLinkCriteria) > 0 Then
    'Undo duplicate entry
    Me.Undo
    'Message box warning of duplication
    MsgBox "Warning Document ID " _
    & SID & " has already been entered." _
    & vbCr & vbCr & "You will now been taken to the record.", _
    vbInformation, "Duplicate Information"
    'Go to record of original Document ID
    rsc.FindFirst stLinkCriteria
    Me.Bookmark = rsc.Bookmark
    End If
    Set rsc = Nothing
    End Sub

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,043
    Hi Emily,

    I never use the build-in switchboard manager but build my own menu's and menuform, but basically a switchboard is a form with buttons that allow the user to navigate along the application. It doesn't have a dataset of its own.
    So if you set rsc as a clone of that form, and then filter it even further I would expect that you get an empty dataset as result, so indeed there is no current record to work with.
    This code should be used in the data-entry form, not the switchboard.

    gr
    NG

  3. #3
    emilyrogers is offline Advanced Beginner
    Windows 98/ME Access 2003
    Join Date
    Oct 2010
    Posts
    46
    So how do i implement my code into the switch board. Basically i want an error box to pop-up when a user trys to put in a document id that has already been used and then i want them to be shown the original record.
    I can make it work in the tables with the information but i dont know how to link this into the main switch board.

  4. #4
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,043
    Hi emili,

    that depends of your forms and the code in it. If you're working from the switchboard you'll probably have to call to the recordsets through ADO, not with the recordsetclone property.

    gr
    NG

  5. #5
    emilyrogers is offline Advanced Beginner
    Windows 98/ME Access 2003
    Join Date
    Oct 2010
    Posts
    46
    so it should be this?

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

    Set rsc = Me.Recordset

    SID = Me.[Document ID].Value
    stLinkCriteria = "[Document ID]=" & "'" & [SID] & "'"


    If DCount("[Document ID]", "[ECNs Pending]", stLinkCriteria) > 0 Then
    'Undo duplicate entry
    Me.Undo
    'Message box warning of duplication
    MsgBox "Warning [Document ID] " & [SID] & " has already been entered." & vbCr & vbCr & "", vbInformation, "Duplicate Information"
    'Go to record of original [Document ID]
    rsc.FindFirst stLinkCriteria
    Me.Bookmark = rsc.Bookmark

    End If

    Set rsc = Nothing

    End Sub

  6. #6
    emilyrogers is offline Advanced Beginner
    Windows 98/ME Access 2003
    Join Date
    Oct 2010
    Posts
    46
    With this code i just keep getting the me.bookmark=rsc.bookmark highlighted and saying that there is no current record. I dont know what to do because i have only been using ms access since midday yesterday!


    Private Sub Document_ID_BeforeUpdate(Cancel As Integer)

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

    Set rsc = Me.Recordset

    SID = Me.[Document ID].Value
    stLinkCriteria = "[Document ID]=" & "'" & [SID] & "'"


    If DCount("[Document ID]", "[ECNs Pending]", stLinkCriteria) > 0 Then
    'Undo duplicate entry
    Me.Undo
    'Message box warning of duplication
    MsgBox "Warning [Document ID] " & [SID] & " has already been entered." & vbCr & vbCr & "", vbInformation, "Duplicate Information"
    'Go to record of original [Document ID]
    rsc.FindFirst stLinkCriteria
    Me.Bookmark = rsc.Bookmark

    End If

    Set rsc = Nothing

    End Sub

  7. #7
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,043
    Hi,

    assuming there is a control on your switchboard named txtDocID that contains the ID of the document that has to be controlled:

    Dim rsc As New ADODB.Recordset

    rsc.Open "select * from tbl??? where [Document ID]= """ & Me.txtDocID & """", CurrentProject.Connection, adOpenDynamic, adLockReadOnly

    With rsc
    If .BOF And .EOF Then 'no records
    .... do here what has to be done if no records are found
    Else
    .MoveFirst
    .... do here what has to be done with the doubles, like opening the form with the focus on that double
    End If
    End With
    rsc.Close



    Set rsc = Nothing

  8. #8
    emilyrogers is offline Advanced Beginner
    Windows 98/ME Access 2003
    Join Date
    Oct 2010
    Posts
    46
    But the whole point of my code is that on entering the document ID they will get a pop-up ONLY if there is already a record with that document ID on the system. I am sorry to be slow but i am very very new to ms access.

  9. #9
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,043
    Hi, then only use:

    With rsc
    If not(.BOF And .EOF) Then
    .MoveFirst
    .... do here what has to be done with the doubles, like opening the form with the focus on that double
    End If
    End With

  10. #10
    emilyrogers is offline Advanced Beginner
    Windows 98/ME Access 2003
    Join Date
    Oct 2010
    Posts
    46
    thank you for your help. now i am getting an error on Me.Bookmark = rs.Bookmark saying object required!
    I am so confused as i dont know what any of this means!


    Private Sub Document_ID_BeforeUpdate(Cancel As Integer)

    Dim SID As String
    Dim stLinkCriteria As String
    Dim rsc As New ADODB.Recordset

    rsc.Open "select* from [ECNs Pending] where [Document ID]= """ & Me.[Document ID] & """", CurrentProject.Connection, adOpenDynamic, adLockReadOnly

    Set recClone = Me.RecordsetClone

    SID = Me.[Document ID].Value

    stLinkCriteria = "[Document ID]=" & "'" & SID & "'"
    'Check [ECNs Pending] table for duplicate [Document ID]

    If DCount("[Document ID]", "[ECNs Pending]", stLinkCriteria) > 0 Then
    'Undo duplicate entry
    Me.Undo

    'Message box warning of duplication
    MsgBox "Warning Document ID " _
    & SID & " has already been entered." _
    & vbCr & vbCr & "You will now been taken to the record.", _
    vbInformation_, "Duplicate Information"

    'Go to record of original Document ID
    recClone.FindFirst stLinkCriteria
    Me.Bookmark = rs.Bookmark
    End If

    rsc.Close

    Set rs = Nothing

    End Sub

  11. #11
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,043
    Emily,

    the solution I provided has nothing to do with recordset clones and bookmarks, so you can't use those with ADODB recordsets. ADODB goes directly to the recordsets in the table and disregards the form.
    It's difficult to really help without knowing more or seeing your app.

    gr
    NG

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

Similar Threads

  1. Code works in full, fails in Runtime
    By stephenaa5 in forum Programming
    Replies: 3
    Last Post: 09-14-2010, 12:30 PM
  2. runtime error 3219
    By Rider570 in forum Programming
    Replies: 3
    Last Post: 07-07-2010, 09:12 PM
  3. runtime error 2448
    By ds_8805 in forum Forms
    Replies: 3
    Last Post: 04-14-2010, 07:32 PM
  4. Help With Runtime Error 4248
    By KLahvic in forum Programming
    Replies: 1
    Last Post: 04-09-2010, 07:47 AM
  5. Runtime 3075 error
    By whm1 in forum Programming
    Replies: 4
    Last Post: 03-24-2010, 02:50 PM

Tags for this Thread

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