Solved

Run-time error 2501 when opening a form

Posted on 2016-09-13
8
42 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 3

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 13

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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 13

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now