Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Run-time error 2501 when opening a form

Posted on 2016-09-13
8
64 Views
Last Modified: 2016-09-30
I receive the following Run-time error 2501 when opening a form which was created in Access 2003, but I am trying to make available now in an Access 2013 dbase.

Option Compare Database
Option Explicit
Dim ProjectCount As Integer

Private Sub cmdDETAIL_Click()
If IsNull([prmEmpNo]) Then
    MsgBox ("No employee selected.")
    [prmEmpNo].SetFocus
    Exit Sub
End If
ProjectCount = NoOfProjects
If ProjectCount <> 0 Then
    Forms![fPREPROJECT]![fProjectData].SetFocus
    ProjectCount = NoOfProjects
Else
    MsgBox ("Selection has no records.")
    Exit Sub
End If
Select Case prmProjectGroup
    Case "Complaints"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fComplain01", acNormal, , , acFormEdit
    Case "Lab"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fComplain01", acNormal, , , acFormEdit
    Case "ASBESTOS-INSP"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fAsbInsp01", acNormal, , , acFormEdit
    Case "Inspect-PERM"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fFacInsp01", acNormal, , , acFormEdit
    Case "Enforcement Cases"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fEnforce01", acNormal, , , acFormEdit
    Case "Projects"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fProject01", acNormal, , , acFormEdit
    Case "Permits"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fPermRev01", acNormal, , , acFormEdit
    Case "Training"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fTraining01", acNormal, , , acFormEdit
    Case Else
        MsgBox ("Type of Project selected does not have detail records.")
        Exit Sub
End Select
End Sub

Private Sub cmdExit_Click()
DoCmd.Echo False
Me.Visible = False
If (SysCmd(acSysCmdGetObjectState, A_FORM, "fAQSplashForm") = 0) Then
  DoCmd.OpenForm "fAQSplashForm"
End If
DoCmd.Echo True
End Sub

Private Sub cmdHELP_Click()
Call NavigHelp
End Sub


Private Sub cmdMemo_Click()

If [Forms]![fPREPROJECT]![fProjectData].Form.CurrentRecord <> 0 Then
    glbProjID = [Forms]![fPREPROJECT]![fProjectData].Form![ipProjID]
    [Forms]![fPREPROJECT]![FormLink1] = [Forms]![fPREPROJECT]![fProjectData].Form![ipProjID]
    DoCmd.OpenForm "fProjMemoPopup"
End If


End Sub



Private Sub Form_Activate()
'Me![fProjectData].SetFocus
'Me![fProjectData].Form![ipProjID].SetFocus
 '           .SelStart = intWhere - 1
'            .SelLength = Len(strSearch
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode <> vbKeyF6 Then Exit Sub
KeyCode = 0
If (SysCmd(acSysCmdGetObjectState, A_FORM, "fAsbFac01") <> 0) Then
    Forms![fAsbFac01].SetFocus
ElseIf (SysCmd(acSysCmdGetObjectState, A_FORM, "fFacDetail01") <> 0) Then
    Forms![fFacDetail01].SetFocus
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
Dim db As DAO.Database
Set db = CurrentDb()
'load the Rowsource for [prmEmpNo]
'code below performs a query and loads information
'from the EMPLOYEE table into the Rowsource
Dim EmpInfo As DAO.Recordset
Dim i As Integer
Dim qte
qte = Chr(34)
Dim prm As Parameter
Dim QD As DAO.QueryDef
    Set QD = db.QueryDefs("qCmbEmpInfo2")
For i = 0 To QD.Parameters.Count - 1
    Set prm = QD.Parameters(i)
    prm.Value = Eval(prm.Name)
Next i
Set EmpInfo = QD.OpenRecordset(dbOpenDynaset)
EmpInfo.MoveFirst
Do Until EmpInfo.EOF
    [prmEmpNo].RowSource = [prmEmpNo].RowSource & qte & EmpInfo![EmpInfo] & qte & ";" & qte & EmpInfo![Empl_No] & qte & ";"
EmpInfo.MoveNext
Loop
EmpInfo.Close
'this adds an additional entriy at the beginning of Rowsource
[prmEmpNo].RowSource = qte & "AllActive" & qte & ";" & qte & "Actv" & qte & ";" & [prmEmpNo].RowSource
'this adds additional entries to the end of Rowsource
[prmEmpNo].RowSource = [prmEmpNo].RowSource & qte & "TOXICS" & qte & ";" & qte & "tox" & qte & ";"
[prmEmpNo].RowSource = [prmEmpNo].RowSource & qte & "STATIONARY SOURCE" & qte & ";" & qte & "cmp" & qte & ";"
[prmEmpNo].RowSource = [prmEmpNo].RowSource & qte & "AllEmployees" & qte & ";" & qte & "AllEmployees" & qte & ";"
'sets values of startup parameter fields
Forms![fPREPROJECT]![prmProjectGroup] = "AllProjects"
Forms![fPREPROJECT]![prmOpenClosed] = 2
Forms![fPREPROJECT]![prmEmpNo] = "Actv"
DoCmd.Maximize
Me![fProjectData].SetFocus

End Sub



Private Sub grpOpenClosed_Click()
Call ResetParms
End Sub



Public Function NoOfProjects()
NoOfProjects = DCount("*", "qProjectData")
End Function

Private Sub Opt1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call RedoSort(1)
'ME: added September 10, 2008
Call RedoSort(1)

End Sub

Private Function RedoSort(OptNo As Integer)
If Me.[grpOpenClosed] = OptNo Then
    Forms![fPREPROJECT]![fProjectData].Form.OrderBy = "[SortDate],  [Due Date], [Project Description]"
End If
'ME:  09/03/2008:  added the following for the Plan Date sorting-this is a test
If OptNo = 5 Then
    Forms![fPREPROJECT]![fProjectData].Form.OrderBy = "[SortDate], [Plan Date], [Project Description]"
End If
End Function

Private Sub Opt2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call RedoSort(2)
'ME: added September 10, 2008
Call RedoSort(2)
End Sub



Private Sub Opt3_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call RedoSort(3)
'ME: added September 10, 2008
Call RedoSort(3)
End Sub


Private Sub Opt4_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call RedoSort(4)
'ME: added September 10, 2008
Call RedoSort(4)
End Sub

Public Function ResetParms()
Call qProjectDataGen(Forms![fPREPROJECT], Forms![fPREPROJECT]![fProjectData].Form)
[Forms]![fPREPROJECT]![fProjectData].Requery
If [Forms]![fPREPROJECT]![fProjectData].[Form].[CurrentRecord] <> 0 Then
    Me![fProjectData].SetFocus
    Me![fProjectData].Form![ipProjID].SetFocus
End If
End Function

Private Sub Opt5_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call RedoSort(5)
'ME: added September 10, 2008
Call RedoSort(5)
End Sub

Private Sub prmEmpNo_Click()
Call ResetParms

End Sub

Private Sub prmProjectGroup_Click()
Call ResetParms

End Sub

Open in new window




During debugging, the following line in the above code is high-lighted as an error...

Case "Complaints"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fComplain01", acNormal, , , acFormEdit
0
Comment
Question by:Tammy Allen
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 4

Expert Comment

by:bfuchs
ID: 41796968
can you open that form from DB container and edit records?
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 41797009
Can you post the database?  I can test it in Access versions from 2003 through 2013.
0
 
LVL 15

Accepted Solution

by:
John Tsioumpris earned 500 total points
ID: 41797791
What if
Case "Complaints":
        If ProjectCount <> 0 Then DoCmd.OpenForm "fComplain01"

Open in new window

0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 41797971
You could try stepping through the code on the form's Open event, and see if any specific line of code triggers the error.
0
 

Author Comment

by:Tammy Allen
ID: 41818548
I have been working on the Access dbase using some of the suggestions provided.  The following code is still not functional. I am unable to load the dbase (very exploded, large file) onto the site.  The dbase is loaded with old DoCMD.OpenForm code.  I believe the issue may be resulting in the condition " If Project count<>0 " based on John's observation.  This condition may not be necessary to open each of the types of forms listed.  Does this sound plausible as a solution.

.

Option Compare Database
Option Explicit
Dim ProjectCount As Integer

Private Sub cmdDETAIL_Click()
If IsNull([prmEmpNo]) Then
    MsgBox ("No employee selected.")
    [prmEmpNo].SetFocus
    Exit Sub
End If
ProjectCount = NoOfProjects
If ProjectCount <> 0 Then
    Forms![fPREPROJECT]![fProjectData].SetFocus
    ProjectCount = NoOfProjects
Else
    MsgBox ("Selection has no records.")
    Exit Sub
End If
Select Case prmProjectGroup
    Case "Complaints"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fComplain01", acNormal, , , acFormEdit
    Case "Lab"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fComplain01", acNormal, , , acFormEdit
    Case "ASBESTOS-INSP"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fAsbInsp01", acNormal, , , acFormEdit
    Case "Inspect-PERM"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fFacInsp01", acNormal, , , acFormEdit
    Case "Enforcement Cases"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fEnforce01", acNormal, , , acFormEdit
    Case "Projects"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fProject01", acNormal, , , acFormEdit
    Case "Permits"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fPermRev01", acNormal, , , acFormEdit
    Case "Training"
        If ProjectCount <> 0 Then DoCmd.OpenForm "fTraining01", acNormal, , , acFormEdit
    Case Else
        MsgBox ("Type of Project selected does not have detail records.")
        Exit Sub
End Select
End Sub

Private Sub cmdExit_Click()
DoCmd.Echo False
Me.Visible = False
If (SysCmd(acSysCmdGetObjectState, A_FORM, "fAQSplashForm") = 0) Then
  DoCmd.OpenForm "fAQSplashForm"
End If
DoCmd.Echo True
End Sub

Private Sub cmdHELP_Click()
Call NavigHelp
End Sub


Private Sub cmdMemo_Click()

If [Forms]![fPREPROJECT]![fProjectData].Form.CurrentRecord <> 0 Then
    glbProjID = [Forms]![fPREPROJECT]![fProjectData].Form![ipProjID]
    [Forms]![fPREPROJECT]![FormLink1] = [Forms]![fPREPROJECT]![fProjectData].Form![ipProjID]
    DoCmd.OpenForm "fProjMemoPopup"
End If


End Sub



Private Sub Form_Activate()
'Me![fProjectData].SetFocus
'Me![fProjectData].Form![ipProjID].SetFocus
 '           .SelStart = intWhere - 1
'            .SelLength = Len(strSearch
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode <> vbKeyF6 Then Exit Sub
KeyCode = 0
If (SysCmd(acSysCmdGetObjectState, A_FORM, "fAsbFac01") <> 0) Then
    Forms![fAsbFac01].SetFocus
ElseIf (SysCmd(acSysCmdGetObjectState, A_FORM, "fFacDetail01") <> 0) Then
    Forms![fFacDetail01].SetFocus
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
Dim db As DAO.Database
Set db = CurrentDb()
'load the Rowsource for [prmEmpNo]
'code below performs a query and loads information
'from the EMPLOYEE table into the Rowsource
Dim EmpInfo As DAO.Recordset
Dim i As Integer
Dim qte
qte = Chr(34)
Dim prm As Parameter
Dim QD As DAO.QueryDef
    Set QD = db.QueryDefs("qCmbEmpInfo2")
For i = 0 To QD.Parameters.Count - 1
    Set prm = QD.Parameters(i)
    prm.Value = Eval(prm.Name)
Next i
Set EmpInfo = QD.OpenRecordset(dbOpenDynaset)
EmpInfo.MoveFirst
Do Until EmpInfo.EOF
    [prmEmpNo].RowSource = [prmEmpNo].RowSource & qte & EmpInfo![EmpInfo] & qte & ";" & qte & EmpInfo![Empl_No] & qte & ";"
EmpInfo.MoveNext
Loop
EmpInfo.Close
'this adds an additional entriy at the beginning of Rowsource
[prmEmpNo].RowSource = qte & "AllActive" & qte & ";" & qte & "Actv" & qte & ";" & [prmEmpNo].RowSource
'this adds additional entries to the end of Rowsource
[prmEmpNo].RowSource = [prmEmpNo].RowSource & qte & "TOXICS" & qte & ";" & qte & "tox" & qte & ";"
[prmEmpNo].RowSource = [prmEmpNo].RowSource & qte & "STATIONARY SOURCE" & qte & ";" & qte & "cmp" & qte & ";"
[prmEmpNo].RowSource = [prmEmpNo].RowSource & qte & "AllEmployees" & qte & ";" & qte & "AllEmployees" & qte & ";"
'sets values of startup parameter fields
Forms![fPREPROJECT]![prmProjectGroup] = "AllProjects"
Forms![fPREPROJECT]![prmOpenClosed] = 2
Forms![fPREPROJECT]![prmEmpNo] = "Actv"
DoCmd.Maximize
Me![fProjectData].SetFocus

End Sub



Private Sub grpOpenClosed_Click()
Call ResetParms
End Sub



Public Function NoOfProjects()
NoOfProjects = DCount("*", "qProjectData")
End Function

Private Sub Opt1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call RedoSort(1)
'ME: added September 10, 2008
Call RedoSort(1)

End Sub

Private Function RedoSort(OptNo As Integer)
If Me.[grpOpenClosed] = OptNo Then
    Forms![fPREPROJECT]![fProjectData].Form.OrderBy = "[SortDate],  [Due Date], [Project Description]"
End If
'ME:  09/03/2008:  added the following for the Plan Date sorting-this is a test
If OptNo = 5 Then
    Forms![fPREPROJECT]![fProjectData].Form.OrderBy = "[SortDate], [Plan Date], [Project Description]"
End If
End Function

Private Sub Opt2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call RedoSort(2)
'ME: added September 10, 2008
Call RedoSort(2)
End Sub



Private Sub Opt3_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call RedoSort(3)
'ME: added September 10, 2008
Call RedoSort(3)
End Sub


Private Sub Opt4_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call RedoSort(4)
'ME: added September 10, 2008
Call RedoSort(4)
End Sub

Public Function ResetParms()
Call qProjectDataGen(Forms![fPREPROJECT], Forms![fPREPROJECT]![fProjectData].Form)
[Forms]![fPREPROJECT]![fProjectData].Requery
If [Forms]![fPREPROJECT]![fProjectData].[Form].[CurrentRecord] <> 0 Then
    Me![fProjectData].SetFocus
    Me![fProjectData].Form![ipProjID].SetFocus
End If
End Function

Private Sub Opt5_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call RedoSort(5)
'ME: added September 10, 2008
Call RedoSort(5)
End Sub

Private Sub prmEmpNo_Click()
Call ResetParms

End Sub

Private Sub prmProjectGroup_Click()
Call ResetParms

End Sub

Open in new window

0
 
LVL 15

Expert Comment

by:John Tsioumpris
ID: 41818578
Well maybe its time to upload a stripped down copy to check what is going on...
0
 

Author Closing Comment

by:Tammy Allen
ID: 41823365
The new code worked and simplified the process.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question