Results 1 to 13 of 13
  1. #1
    paddon is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    24

    Runtime Error 3021

    Hello all,

    In my database I have a contact list form, upon which one can click the last name of an individual and a contact details form is launched, at that record. This code was working fine but decided to stop working today. I keep receiving a Runtime Error '3021': No Current Record when I click the name...



    Here is the code:

    Code:
    Private Sub Last_Name_Click()
    
        Dim rs As Object
        Dim lngBookmark2 As Long
    
        'set a variable to the current record
        lngBookmark2 = Me.OwnersID
        'open the new form
        DoCmd.OpenForm "D_Contact"
    
        'take it to the selected record
        Set rs = Forms!D_Contact.RecordsetClone
        rs.FindFirst "OwnersID = " & lngBookmark2
        Forms!D_Contact.Bookmark = rs.Bookmark
    
        Set rs = Nothing
        
    End Sub
    Any help would be greatly appreciated.

    Thanks,
    Jeff Paddon
    Last edited by paddon; 03-14-2011 at 12:14 PM.

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,288
    You need to check the NoMatch property after a find. Also, you could use a message box to see the value in OwnersID.

    Try this:

    Code:
    Private Sub Last_Name_Click()
    
       Dim rs As Object
       Dim lngBookmark2 As Long
    
       'set a variable to the current record
       lngBookmark2 = Me.OwnersID
    
       '   -----comment out later----
       MsgBox "OwnersID = " & Me.OwnersID
       '   --------------------------
       'open the new form
       DoCmd.OpenForm "D_Contact"
    
       'take it to the selected record
       Set rs = Forms!D_Contact.RecordsetClone
       rs.FindFirst "OwnersID = " & lngBookmark2
       If rs.NoMatch Then
          MsgBox "check OwnersID"
       Else
          Forms!D_Contact.Bookmark = rs.Bookmark
       End If
    
       Set rs = Nothing
    
    End Sub
    Or you might try this:

    Code:
    Private Sub Last_Name_Click()
    
       'open the new form
       DoCmd.OpenForm "D_Contact", acNormal, , "OwnerID = " & Me.OwnersID
    
    End Sub
    HTH
    -----
    Steve
    --------------------------------
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

  3. #3
    paddon is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    24
    I've decided to implement your second suggestion as simplifying things seems more reasonable at this point.

    However, now when I click it I just get a blank details form but no error message. It still does not open with the correct record.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,288
    OK, try this:


    Code:
    Private Sub Last_Name_Click()
    
      If IsNull(Me.Ownersid) Then
        MsgBox "invalid Ownersid"
      Else
        ' next line can be commented out later
        ' display ownersID
        MsgBox Me.Ownersid
        'open the new form
        DoCmd.OpenForm "D_Contact", acNormal, , "OwnerID = " & Me.Ownersid
      End If
    End Sub
    BTW, is OwnersID is numeric or text (field definition is the table)?
    Last edited by ssanfu; 03-08-2011 at 04:52 PM. Reason: spelling
    HTH
    -----
    Steve
    --------------------------------
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

  5. #5
    paddon is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    24
    OwnersID is numeric. When the message box shows the number it is the correct ID for the one that I clicked on.

    The second message box is not shown, however, the details form opens to a blank form, not the record I'm expecting.

  6. #6
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,288
    If you change the open form line to

    DoCmd.OpenForm "D_Contact", acNormal, , "OwnerID = 100"

    and change the 100 to a valid OwnerID, does the correct record appear?
    HTH
    -----
    Steve
    --------------------------------
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

  7. #7
    paddon is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    24
    No even then the details form still opens to a blank record.

  8. #8
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,288
    Putting in a value should have worked. OK, would you post the record source SQL of the details form??
    HTH
    -----
    Steve
    --------------------------------
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

  9. #9
    paddon is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    24
    Record source is just the "Contacts" Table, which contains all records and does include the ownersID.

  10. #10
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,288
    Without having the database to look at, the only other thing I can think of is the form is corrupted. (and I only have access to A2007 at home / A2003 at work)

    Create a new basic form, bind it to the Contacts table, put a couple of text boxes on it and add a button. In the click event, add

    Code:
    DoCmd.OpenForm "New_Contact", acNormal, , "OwnerID = 100"
    Name it "New_Contact". Again, change 100 to a valid owner ID. Does the new form open to the correct ID?

    If the new form opens to the correct ID, delete "D_Contact"and recreate it.
    HTH
    -----
    Steve
    --------------------------------
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

  11. #11
    paddon is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    24
    The new form does. What's the story behind the forms being corrupted? I hadn't changed anything on them or within the tables...

    Seems like an odd error but I have heard of forms being corrupted before.

  12. #12
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,288
    Glad you got it working.

    There are (and have been) lots of causes of corruption. One known cause is having autocorrect turned on. This is not spelling autocorrect. It is name auotcorrect. If you rename a table, it tries to change the name of the table everywhere it is used - forms, queries reports,... What is usually does is corrupt something. I have lost entire databases until I found out about it. The first thing I do when creating a new database is make sure "name autocorrect" is turned off. If I look at someone else's database, first thing to check and turn off is name auotcorrect.
    In A2K7 (probably the same in A2K10), click on the round button in the upper left hand of the Access screen, click on "Access Options" at the bottom of the dialog box, then "Current Database". Look in the right hand pane for "Name Autocorrect Options". Make sure all 3 options are unchecked.

    Another cause is if a database is being accessed by several people from a shortcut. The database should be split, everyone should have their own copy of the front end (FE) and the back end (BE) should be on a server.

    It could also have been caused by a glitch when shutting down. Or you didn't hold your breath for long enough.

    Don't you just love backups???
    HTH
    -----
    Steve
    --------------------------------
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

  13. #13
    paddon is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    24
    I do love backups haha. There are only a few records that weren't backed up since the last working version so I just restored it to save from re-creating all the forms. I was just very curious as to what happened!

    Thanks very much for the help everyone!

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

Similar Threads

  1. Error in Runtime Only
    By drunkinmunki in forum Programming
    Replies: 7
    Last Post: 12-16-2010, 03:43 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

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 - Senior Forums