Error 3012: no current record on CLOSE of a "read only" form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swen
    New Member
    • Jan 2011
    • 18

    Error 3012: no current record on CLOSE of a "read only" form

    I am currently working on an existing MS Access 03 data base that has been working perfectly for years. I have been requested to provide the userS the option to select a viewing option on a form, i.e. open as read only -v- edit.

    The form currently has error trapping code everywhere and works fine when the form is opened with (current code):
    Code:
    DoCmd.OpenForm strFormName, acNormal, , , [B]acFormEdit[/B], acWindowNormal, strSQL3
    However when the form is triggered to opened with (new code):
    Code:
    DoCmd.OpenForm strFormName, acNormal, , , [B]acFormReadOnly[/B], acWindowNormal, strSQL3
    I get the error code 3021 no current record upon the CLOSE of the form only. I have tried to debug this with no success. The 3021 error is triggered BEFORE any of the vb code is triggered. I have looked extensively for a solution and have yet to fine one.

    Any help would be appreciated.
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    Sven,
    When the error code pops ups, what happens if you hit control/break? You should get into debug mode at the error message. Once you find where the error message is, make sure it is followed by
    Code:
    Resume next
    If not, add that line. Then step through the code with F8 after the error message and you'll see what line of code actually triggered the error.

    Jim

    Comment

    • swen
      New Member
      • Jan 2011
      • 18

      #3
      jimatqsi,
      Using the "control/break" only takes me to debugging and engages the "on close" code, without any errors. I get the 3021 error BEFORE any VB code is ran.

      Unfortunately this is NOT my database, I have been asked to update it. The builder did not provide a button control to close the form, so users have to use the forms control box "X" to close. Just out of curiosity, I built a button control for the users to use and removed the control box "X" close... I got the same error 3021 PRIOR to the close code running.

      Any thoughts?

      Comment

      • mcupito
        Contributor
        • Aug 2013
        • 294

        #4
        Well when you close the form in order to open this new form, what is the code there? Is something being edited? A module being ran? A public function being called?

        Also, is the first form editable where the error is being thrown? It seems like it's in edit mode. Perhaps, on the before update event of that form, put in something like

        Code:
        Private Sub Form_BeforeUpdate(Cancel As Integer)
        If Me.Dirty Then
          If MsgBox("This form is attempting to save something", vbOKCancel, "Save?") = vbCancel Then
            Me.Undo
          End If
        End If
        End Sub
        At this point, maybe we can narrow down the issue.

        Comment

        • swen
          New Member
          • Jan 2011
          • 18

          #5
          mcupito,
          The same form is used, the change is how it is opened. Users where making unintended changes to data, thus the request to allow the user to make a selection to open the form as "read only"(View) or Edit. Based on the selection made, now an If statement runs the Docmd...acFormEdit (original) -v- acFormReadOnly.

          The user has the option to open ALL records (over 40,000) or via search criteria. The record source is based on a query. ALL forms, including this one, have code to check for and trap any errors related to EOF and BOF, and if no record is found, a msg box appears informing the user and will not open the form.

          Everything works great until the form is opened as “read only”, regardless if one record or 40 records are pulled. When the read only version is closed, the 3021 error occurs before any code runs.

          Could this be a relationship issue with the tables? I think I read something, somewhere on it.

          Comment

          • mcupito
            Contributor
            • Aug 2013
            • 294

            #6
            So when the form is opened as ReadOnly, what are the users doing on the form?

            Comment

            • swen
              New Member
              • Jan 2011
              • 18

              #7
              Several departments review the data, for whatever their job function needs, (customer inquiry, quality standards, employee review, etc…) Not my place to question. Errors with data had happened when the user inadvertently; click a button, start typing in a field, etc… Thus, the request to make a View (read only) option available.

              With Read only, if multiple records are pulled, the user only has the ability to navigate from one record to the next. If only one record is pulled, navigation is not available. All other functions, (i.e. edit, add, delete), are not available and the creation of yet another form and more code is not needed.

              Comment

              • mcupito
                Contributor
                • Aug 2013
                • 294

                #8
                And the Read Only form is the one that is throwing the error: 3021. Is there a SubForm involved at any point?

                Worst comes to worst, you can comment out the Error Handleror throw the exception
                Code:
                (pseudo-code)
                If Err.Number <> 3021
                Especially if nothing disruptive is coming of it, and it's just an annoyance.

                Comment

                • swen
                  New Member
                  • Jan 2011
                  • 18

                  #9
                  Yes. Only the "Read Only" has the issue.
                  Yes. There is one SubForm

                  All forms already have error handling that include the: If Err.Number <> 3021 and EOF/BOF language.

                  The strange part is the 3021 error comes up BEFORE any VB code is ran. I have debugged everything and nothing errors via code.

                  Comment

                  • zmbd
                    Recognized Expert Moderator Expert
                    • Mar 2012
                    • 5501

                    #10
                    OK, STOP! We're chasing our tails here without a clue as to where the true issue is:

                    SWEN:
                    Please post your code.
                    Both the ORIGINAL code and your changed code.
                    Please, click on the [CODE/] button in the post toolbar and then cut and paste your script between the [CODE] [/CODE] tags.

                    Comment

                    • swen
                      New Member
                      • Jan 2011
                      • 18

                      #11
                      Zmbd

                      As you requested

                      I get the error code 3021 (no current record) upon the CLOSE of the “READ ONLY” version of the form only. I get the error BEFORE the "on close" code is ran.

                      The ONLY code that has been changed is how the form is opened. The form itself does not have any changes. Its code already has code to trap for 3021 and EOF/BOF. Again, I get the error BEFORE code is ran when the "READ ONLY" version is closed.


                      Code 1. (ORIGIONAL)
                      Code:
                      DoCmd.OpenForm strFormName, acNormal, , , acFormEdit, acWindowNormal, strSQL3

                      CHANGED TO:
                      Code 2

                      Code:
                      If Me.FrameA = 1 Then   'EDITABLE (UNCHANGED CODE)
                      	DoCmd.OpenForm strFormName, acNormal, , , acFormEdit, acWindowNormal, strSQL3
                      Else   'NONeditable (VIEW ONLY, READ ONLY)
                      	DoCmd.OpenForm strFormName, acNormal, , , acFormReadOnly, acWindowNormal, strSQL3  
                      End If

                      Comment

                      • zmbd
                        Recognized Expert Moderator Expert
                        • Mar 2012
                        • 5501

                        #12
                        You need to review the entire original code.
                        More than likely, there is a focus or a new record being set or some other code that is forcing the issue.

                        Look at the events for on open, on load, current, on close, on unload, etc...
                        Last edited by zmbd; Apr 8 '14, 08:14 PM.

                        Comment

                        • swen
                          New Member
                          • Jan 2011
                          • 18

                          #13
                          Sorry for taking so long to get back on this. I have reviewed all the code and ALL is good. Everything is working fine now.

                          Our Network folks recently informed me they were changing settings (and various other things) on the servers during the time I was working on this. Does anyone else “enjoy” it when server work is being done and no one bothers to inform you?

                          I placed a "Close" button on the form with additional trapping code just in case this happens again.

                          I want to thank everyone for all your help.

                          Comment

                          • zmbd
                            Recognized Expert Moderator Expert
                            • Mar 2012
                            • 5501

                            #14
                            Does anyone else “enjoy” it when server work is being done and no one bothers to inform you?
                            ... about like having dental work without the anesthetic.

                            Thank you for taking the time to get back to us with the final resolution!

                            (^_^)

                            Comment

                            Working...