Results 1 to 12 of 12
  1. #1
    TheBradish is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2017
    Posts
    4

    Run-time error 2501 for one user on one PC

    We keep a database on a network location and it is accessed by the whole company. A few months ago I started having problems when trying to open some forms where the OpenForm action was being cancelled. As far as I know I am the only one in the company having this problem, and only when using my PC (i.e. when I log onto another computer there is no problem). To make things more interesting, if I log on as a different user on my own PC the forms work properly.



    Since the database works for other users I really don't want to change anything about the structure or the code. I have heard reports about the default printer causing this problem, but switching to another default printer has no effect.

    I don't have a much Access experience, and I'm not proficient in VBA, but I know enough to get around a bit. After some extensive debugging this is what I can observe:
    • Error 2501 is triggered at an OpenForm command from the calling form
    • I can manually open the offending forms in Design View
    • Switching to any other view will produce the error:
      "The expression On Open you entered as the event property setting produced the following error: Variable not defined."
    • If I delete code for the Form_Open event, or if I delete "[Event Procedure]" from the Property Sheet, I will get similar errors for any following events which are shown in the Property Sheet as "[Event Procedure]".
    • The error will occur even if the event code contains no commands other than a beginning/ending statement


    I'm really at a loss as to what could be happening here, especially because it is only a problem for my user profile on this one particular PC. Anyone have some ideas?

    Click image for larger version. 

Name:	variable not defined.PNG 
Views:	22 
Size:	20.5 KB 
ID:	29010

  2. #2
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Its looking for a variable, so we need to figure out what that variable is, and where it should be coming from. Can you show us the code causing the error?

  3. #3
    TheBradish is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2017
    Posts
    4
    All code for this form is below. The Form_Current event doesn't seem to exist; the Form_Open sub is in blue. There are no variables in this sub except for the references to a combobox. Even so, if I delete or comment out everything inside that sub it will still throw an error.

    Code:
    Option Compare DatabaseOption Explicit
    
    
    Private Sub cmdGo_Click()
    Dim stOption
    Dim stForm
    Dim stSearchValue
    stOption = [FrameGageType].Value
    
    
        If [FrameGageType].Value = 1 Then
            
            DoCmd.OpenForm "frmPinSetSearch"
            
        End If
        
        If FrameGageType.Value = 2 Then
            
            DoCmd.OpenForm "frmMasterGearSearch"
        End If
                
        If FrameGageType.Value = 3 Then
            
            DoCmd.OpenForm "frmattribwrkhldsearch"
        End If
            
        If FrameGageType.Value = 4 And Not IsNull(Me![comboSN]) Then
            stOption = "rptqryGageMaster"
            DoCmd.OpenReport stOption, acViewPreview
        End If
          
        If FrameGageType.Value = 4 And IsNull(Me![comboSN]) Then
                MsgBox ("You Must select a Gage Serial Number")
                comboSN.SetFocus
        End If
    
    
    End Sub
    
    
    Private Sub Command33_Click()
    comboSN.Value = Null
    comboSN.RowSource = ""
    End Sub
    
    
    Private Sub Form_Open(Cancel As Integer)
    'Clear Select S/N Combo box
    
    
    comboSN.Value = Null
    comboSN.Enabled = False
    End Sub
    
    
    Private Sub Option11_GotFocus()
    comboSN.Enabled = False
    'comboSN.Enabled = True
    'comboSN.Value = Null
    'comboSN.RowSource = "SELECT DISTINCTROW [tblGageMaster].[GageNo] FROM [tblGageMaster];"
    End Sub
    
    
    Private Sub Option13_GotFocus()
    comboSN.Enabled = False
    'comboSN.Enabled = True
    'comboSN.Value = Null
    'comboSN.RowSource = "SELECT DISTINCTROW [tblMasterGear].[GageNo] FROM [tblMasterGear];"
    End Sub
    
    
    
    
    Private Sub optMasterGear_Click()
    Dim stForm
    stForm = "frmMasterGear"
    DoCmd.OpenForm (stForm)
    optPinSet.Value = Null
    optMasterGear.Value = Null
    OptSpecialGauging.Value = Null
    End Sub
    
    
    Private Sub optPinSet_Click()
    Dim stForm
    stForm = "frmGageMaster"
    DoCmd.OpenForm (stForm)
    optPinSet.Value = Null
    optMasterGear.Value = Null
    OptSpecialGauging.Value = Null
    End Sub
    
    
    Private Sub Option20_GotFocus()
    
    
    End Sub
    
    
    Private Sub Option22_GotFocus()
    comboSN.Enabled = True
    comboSN.Value = Null
    End Sub
    
    
    Private Sub Option15_GotFocus()
    comboSN.Enabled = False
    End Sub
    
    
    Private Sub Option39_GotFocus()
    comboSN.Enabled = True
    
    
    End Sub
    Click image for larger version. 

Name:	Property sheet.PNG 
Views:	20 
Size:	14.9 KB 
ID:	29011

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by TheBradish View Post
    We keep a database on a network location and it is accessed by the whole company.
    Is the dB split into a FE and a BE with the BE on the network?

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,698
    May be corruption. Get a fresh copy of the FE for your computer.
    I assume you've tried compact/repair.

  6. #6
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,358
    Sorry to say many errors and omissions in this code, some of which definitely can cause your issue IMHO.
    I'll assume this is just a posting error and is in fact, 2 lines
    Option Compare DatabaseOption Explicit

    these are all variants because they have not been explicitly declared otherwise:
    Dim stOption
    Dim stForm
    Dim stSearchValue


    so you are passing what looks like a form reference to a variant type of variable
    stOption = "rptqryGageMaster"

    these are not properly referenced:
    comboSN.Value = Null
    comboSN.RowSource = ""
    preface with Me. as in Me.comboSN.Value = Null, or better yet, Me.comboSN = Null

    again, not properly referenced (which may be the reason for your error)...
    Private Sub Form_Open(Cancel As Integer)
    'Clear Select S/N Combo box

    ... because Access can/will decipher this as a variable
    comboSN.Value = Null
    comboSN.Enabled = False
    I recently posted that using Me! will cause late bound interpretation of the reference, whereas Me. will cause such references to be interpreted when code is compiled. This means that problems don't arise until run-time. I have to presume that not using Me at all when Option Explicit has been set produces the same result. Either that or the first line of your module is written wrong (but I doubt it). Note that I'm only referring to what happens with Me and not any other use of the bang (!) operator.

    the only way you can correctly write code like this
    optPinSet.Value = Null
    optMasterGear.Value = Null
    OptSpecialGauging.Value = Null

    is if you wrap it in a With block, but the block must begin with the proper parent reference (Me)
    With Me
    .optPinSet = Null
    .optMasterGear = Null
    .OptSpecialGauging = Null
    End With

    Each error I've identified occurs throughout the module, so there's a lot more of it. I suspect it propagates throughout the whole project. Try fixing all of this and see what happens, though it wouldn't explain why you seem to be the only one affected. This suggests you have a different copy of a split FE, so please do answer ssanfu's question as it will help us if what I'm pointing out doesn't fix the problem.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    TheBradish is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2017
    Posts
    4
    Thanks for your help so far. I don't know the answers to some of these questions because I'm not the developer here and I'm brand new to Access, so I appreciate your patience.

    • This is not a split database
    • I have tried compact/repair with no improvement
    • I have tried making new copies of the database from the network location with no improvement
    • I have tried using the With.Me block as suggested with no improvement
    • micron is correct about the posting error in the first line: the two Option statements are on separate lines in the actual code window


    There are things I can do to fix individual occurrences of this error (which is present throughout the project). Things that fix individual occurrences are:
    • turning off Option Explicit
    • deleting "[Event Procedure]" from the event property
    • using the macro builder instead of the code builder to handle events


    Whatever the problems with the code and the properties, however, (there are many) I still cannot change them because the database is working properly for the rest of the company, and it used to work for me until recently.

    My suspicion is that a setting was changed or something was updated on my user profile on my PC that changed the way Access is behaving. I have tried checking my library references, but beyond that I don't have a clue what to look for.

  8. #8
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,358
    it is only a problem for my user profile on this one particular PC
    this suggests an issue with Trusted Locations. Everything else about the situation suggests corruption (many users, db not split = not good). I presume the error happens when you are opening forms normally (switching to form from design view doesn't count). Given these factors, I don't know what to suggest short of importing all objects into a fresh db, but I'm not highly confident on that as a fix. I think the biggest problem, for whatever reason, is that you seem to be constrained with respect to fixing all that is wrong with it.

    For now, your last sentence is probably your best train of thought - what changed at your point? A new PC? Updated profile? Database login password? Office upgrade? and so on.
    To me, this
    I have tried checking my library references
    is irrelevant since the db is not split.

  9. #9
    TheBradish is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2017
    Posts
    4
    I think our IT dept was doing some network maintenance, but beyond that I'm not aware of anything that might have changed. I haven't knowingly changed or updated anything around the time when this problem started. Maybe I have an application that runs automatic updates.

    When I spoke to our IT guy he suggested that he could delete my user profile from the computer and give me a fresh start, but preferred not to do it. I might just have to lean on him a little bit.

    Thanks a lot for all the help.

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by TheBradish View Post
    • This is not a split database
    Just a further warning. As Micron said, many users, db not split = not good.

    This is an excellent way to corrupt your dB, losing everything (I hope you are doing regular daily backups).
    It is a known cause of dB corruption. It may not have corrupted yet, it may not corrupt tomorrow, but it WILL corrupt eventually.

    Each user should have a copy of the FE on their computer; the BE would be on a server or common available computer.
    The BE has only the tables. The FE has everything else.

    Google "split database" and/or "FE" , "BE"...


    Good luck........

  11. #11
    soakwell is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2017
    Posts
    1
    Hi Bradish
    I have recently had the same problem. I set up a new user on a computer with our existing FE on it.
    When logged in as the new user I loose functionality similar to your problems. When I revert to original user account it works fine.
    I have the same database FE operating on different PC's and they work perfectly!
    Did you find a solution?

    Thanks

    Steve
    Steve

  12. #12
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,836
    it may not corrupt tomorrow, but it WILL corrupt eventually
    I would suggest that what the OP is experiencing is in fact the early signs of corruption. And it won't just get progressively worse, it will just stop working.

    The fact there is an [Event Procedure] against the form current event and no code is also an indicator. There may well have been code which is now lost through corruption, but the form object doesn't recognise that fact. Or the converse is true, the form object is corrupted and has been assigned a non existent event

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

Similar Threads

  1. Replies: 6
    Last Post: 10-21-2014, 12:25 PM
  2. Replies: 6
    Last Post: 11-28-2012, 03:43 PM
  3. Suppressed run time error 2501
    By RachelBedi in forum Programming
    Replies: 8
    Last Post: 10-24-2012, 12:26 PM
  4. Replies: 15
    Last Post: 07-26-2012, 02:06 PM
  5. Replies: 7
    Last Post: 07-18-2012, 07:53 AM

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