Run-time Error 5 "Invalid Procedure Call or Argument"

ABE86

New member
Local time
Today, 22:00
Joined
May 10, 2023
Messages
10
hello all.
this is my very first post o a forum, so please don't mind my lack of knowledge or my spelling mistakes.
i'm also a newbie in access development trying to wrap my head around vba.
i got stuck on this Run-time Error 5 "Invalid Procedure Call or Argument" for weeks.

i have a main form on which i have an object called box1 and some command buttons that changes the .sourceobject of box1 to some other additional forms, applying filters to them in most cases. the other two forms use a custom funtion called fLiveSearch to filter results in a listbox control and they both work well independently. but when i try to apply a filtre via vba from the main form, frmPersonal generates the above error.
debug mode highlights line 56 in the frmPersonal code, apparently doesn't like the me. reference in me.filteron, me.filter, me.txtSearch.value and so on... saying that the object is closed or does not exist. i've tryed to replace me. with form_frmPersonal and forms!frmPersonal, but i get some other errors. i'm guessing that the form set as sourceobject to the box1 control its not loaded therefore it cannot find the expression me.txtSearch.Value generating the invalid argument error. the error occurs only when i try to apply the filter via vba from the main form.

any idea on how i could get over it?
works on this form Private Sub btnCursuriCatb_Click() Me.Box1.SourceObject = "frmcursuri" Me.Box1.Form.Filter = "tblCatCurs_ID=2" Me.Box1.Form.FilterOn = True Me.Box1.SetFocus Me.Box1.Form.Requery End Sub

doesn't on this one Private Sub btnPersRES_Click() Me.Box1.SourceObject = "frmPersonal" Me.Box1.Form.Filter = "tblSubunitate_ID=1" Me.Box1.Form.FilterOn = True Me.Box1.SetFocus Me.Box1.Form.Requery End Sub [ICODE]
 
hello all.
this is my very first post o a forum, so please don't mind my lack of knowledge or my spelling mistakes.
i'm also a newbie in access development trying to wrap my head around vba.
i got stuck on this Run-time Error 5 "Invalid Procedure Call or Argument" for weeks.

i have a main form on which i have an object called box1 and some command buttons that changes the .sourceobject of box1 to some other additional forms, applying filters to them in most cases. the other two forms use a custom funtion called fLiveSearch to filter results in a listbox control and they both work well independently. but when i try to apply a filtre via vba from the main form, frmPersonal generates the above error.
debug mode highlights line 56 in the frmPersonal code, apparently doesn't like the me. reference in me.filteron, me.filter, me.txtSearch.value and so on... saying that the object is closed or does not exist. i've tryed to replace me. with form_frmPersonal and forms!frmPersonal, but i get some other errors. i'm guessing that the form set as sourceobject to the box1 control its not loaded therefore it cannot find the expression me.txtSearch.Value generating the invalid argument error. the error occurs only when i try to apply the filter via vba from the main form.

any idea on how i could get over it?
works on this form Private Sub btnCursuriCatb_Click() Me.Box1.SourceObject = "frmcursuri" Me.Box1.Form.Filter = "tblCatCurs_ID=2" Me.Box1.Form.FilterOn = True Me.Box1.SetFocus Me.Box1.Form.Requery End Sub

doesn't on this one Private Sub btnPersRES_Click() Me.Box1.SourceObject = "frmPersonal" Me.Box1.Form.Filter = "tblSubunitate_ID=1" Me.Box1.Form.FilterOn = True Me.Box1.SetFocus Me.Box1.Form.Requery End Sub [ICODE]
Code:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmCursuri"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private blnSpace As Boolean

Private Sub btnClearFilter_Click()
On Error Resume Next
    Me.txtSearch.Value = ""
    txtSearch_Change
End Sub

Private Sub btnClearFilter_Enter()
    Me.txtSearch.Value = ""
    txtSearch_Change
End Sub

Private Sub lstItems_AfterUpdate()
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[ID] = " & Str(Nz(Me![lstItems], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Private Sub txtSearch_Change()
Dim strFullList       As String
Dim strFilteredList   As String

    If blnSpace = False Then
        Me.Refresh
        If Me.FilterOn = True Then
            strFullList = "SELECT tblCursuri.ID, tblCursuri.Denumire, tblCursuri.Descriere FROM tblCursuri WHERE " & Me.Filter & " ORDER BY tblCursuri.tblCatCurs_ID;"
            strFilteredList = "SELECT tblCursuri.ID, tblCursuri.Denumire, tblCursuri.Descriere FROM tblCursuri WHERE " & Me.Filter & " AND [Denumire] LIKE ""*" & Me.txtSearch.Value & _
                "*"" OR " & Me.Filter & " AND [Descriere] LIKE ""*" & Me.txtSearch.Value & "*"" ORDER BY tblCursuri.ID;"
        Else
            strFullList = "SELECT tblCursuri.ID, tblCursuri.Denumire, tblCursuri.Descriere FROM tblCursuri ORDER BY tblCursuri.tblCatCurs_ID;"
            strFilteredList = "SELECT tblCursuri.ID, tblCursuri.Denumire, tblCursuri.Descriere FROM tblCursuri WHERE [Denumire] LIKE ""*" & Me.txtSearch.Value & _
                "*"" OR [Descriere] LIKE ""*" & Me.txtSearch.Value & "*"" ORDER BY tblCursuri.ID;"
        End If
        fLiveSearch Me.txtSearch, Me.lstItems, strFullList, strFilteredList, Me.txtCount
    End If
End Sub

Private Sub txtSearch_KeyPress(KeyAscii As Integer)
    On Error GoTo err_handle
    If KeyAscii = 32 Then
        blnSpace = True
    Else
        blnSpace = False
    End If
    Exit Sub
err_handle:
    Select Case Err.Number
    Case Else
        MsgBox "An unexpected error has occurred: " & vbCrLf & Err.Description & _
            vbCrLf & "Error " & Err.Number & "(" & Erl & ")"
    End Select
End Sub

Private Sub txtSearch_GotFocus()
    On Error Resume Next
    If Me.txtSearch.Value = "(Cautare)" Then
        Me.txtSearch.Value = ""
    End If
End Sub

Private Sub txtSearch_LostFocus()
    On Error Resume Next
    If Me.txtSearch.Value = "" Then
        Me.txtSearch.Value = "(Cautare)"
    End If
End Sub

Private Sub Form_Current()
    txtSearch_Change
    lstItems.SetFocus
 End Sub
'------------------------------------------------------------
' btnEditCurs_Click
'
'------------------------------------------------------------
Private Sub btnEditCurs_Click()

    DoCmd.OpenForm "frmEditCursuri", acNormal, "", "[ID]=Forms![Accordion_MainMenu].Box1!ID", , acNormal

End Sub


'------------------------------------------------------------
' btnCatCursParticipanti_Click
'
'------------------------------------------------------------
Private Sub btnCatCursParticipanti_Click()

    DoCmd.OpenReport "rptCatCursParticipanti", acViewReport, "", "[tblCatCurs_ID]=Forms![Accordion_MainMenu].box1![tblCatCurs_ID]", acNormal

End Sub


'------------------------------------------------------------
' btnSerie_Click
'
'------------------------------------------------------------
Private Sub btnSerie_Click()

    DoCmd.OpenForm "frmSerieCurs", acNormal, "", "", acAdd, acNormal
    Forms!frmSerieCurs!tblCursuri_ID = Forms![accordion_mainmenu].Box1!ID

End Sub
 
hello all.
this is my very first post o a forum, so please don't mind my lack of knowledge or my spelling mistakes.
i'm also a newbie in access development trying to wrap my head around vba.
i got stuck on this Run-time Error 5 "Invalid Procedure Call or Argument" for weeks.

i have a main form on which i have an object called box1 and some command buttons that changes the .sourceobject of box1 to some other additional forms, applying filters to them in most cases. the other two forms use a custom funtion called fLiveSearch to filter results in a listbox control and they both work well independently. but when i try to apply a filtre via vba from the main form, frmPersonal generates the above error.
debug mode highlights line 56 in the frmPersonal code, apparently doesn't like the me. reference in me.filteron, me.filter, me.txtSearch.value and so on... saying that the object is closed or does not exist. i've tryed to replace me. with form_frmPersonal and forms!frmPersonal, but i get some other errors. i'm guessing that the form set as sourceobject to the box1 control its not loaded therefore it cannot find the expression me.txtSearch.Value generating the invalid argument error. the error occurs only when i try to apply the filter via vba from the main form.

any idea on how i could get over it?
works on this form Private Sub btnCursuriCatb_Click() Me.Box1.SourceObject = "frmcursuri" Me.Box1.Form.Filter = "tblCatCurs_ID=2" Me.Box1.Form.FilterOn = True Me.Box1.SetFocus Me.Box1.Form.Requery End Sub

doesn't on this one Private Sub btnPersRES_Click() Me.Box1.SourceObject = "frmPersonal" Me.Box1.Form.Filter = "tblSubunitate_ID=1" Me.Box1.Form.FilterOn = True Me.Box1.SetFocus Me.Box1.Form.Requery End Sub [ICODE]
Code:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Form_frmPersonal"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Option Explicit

Private blnSpace As Boolean

Private Sub CommandFirstRecord_Click()
    DoCmd.GoToRecord , "", acFirst
End Sub

Private Sub CommandPreviousRecord_Click()
    DoCmd.GoToRecord , "", acPrevious
End Sub

Private Sub CommandNextRecord_Click()
    DoCmd.GoToRecord , "", acNext
End Sub

Private Sub CommandLastRecord_Click()
    DoCmd.GoToRecord , "", acLast
End Sub

Private Sub btnClearFilter_Click()
On Error Resume Next
    Me.txtSearch.Value = ""
    txtSearch_Change
End Sub

Private Sub btnClearFilter_Enter()
    Me.txtSearch.Value = ""
    txtSearch_Change
End Sub

Private Sub lstItems_AfterUpdate()
    Dim rs As Object
    
    Set rs = Me.Recordset.Clone
    rs.FindFirst "[ID] = " & Str(Nz(Me![lstItems], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Private Sub txtSearch_Change()
Dim strFullList       As String
Dim strFilteredList   As String
    
    If blnSpace = False Then
        Me.Refresh
        If Me.FilterOn = True Then
            strFullList = "SELECT qryPersonal.ID, [grad] & ' ' & [nume] & ' ' & [prenume] AS [Grad, nume si prenume] FROM qryPersonal WHERE " & Me.Filter & " ORDER BY qryPersonal.Nume, qryPersonal.Prenume;"
            strFilteredList = "SELECT qryPersonal.ID, [grad] & ' ' & [nume] & ' ' & [prenume] AS [Grad, nume si prenume] FROM qryPersonal WHERE " & Me.Filter & " AND [nume] LIKE ""*" & Me.txtSearch.Value & _
                "*"" OR " & Me.Filter & " AND [prenume] LIKE ""*" & Me.txtSearch.Value & "*"" ORDER BY qryPersonal.Nume, qryPersonal.Prenume;"
        Else
            strFullList = "SELECT qryPersonal.ID, [grad] & ' ' & [nume] & ' ' & [prenume] AS [Grad, nume si prenume] FROM qryPersonal ORDER BY qryPersonal.Nume, qryPersonal.Prenume;"
            strFilteredList = "SELECT qryPersonal.ID, [grad] & ' ' & [nume] & ' ' & [prenume] AS [Grad, nume si prenume] FROM qryPersonal WHERE [nume] LIKE ""*" & Me.txtSearch.Value & _
                "*"" OR [prenume] LIKE ""*" & Me.txtSearch.Value & "*"" ORDER BY qryPersonal.Nume, qryPersonal.Prenume;"
        End If
        fLiveSearch Me.txtSearch, Me.lstItems, strFullList, strFilteredList
    End If
End Sub

Private Sub txtSearch_KeyPress(KeyAscii As Integer)
    On Error GoTo err_handle
    If KeyAscii = 32 Then
        blnSpace = True
    Else
        blnSpace = False
    End If
    Exit Sub
err_handle:
    Select Case Err.Number
    Case Else
        MsgBox "An unexpected error has occurred: " & vbCrLf & Err.Description & _
            vbCrLf & "Error " & Err.Number & "(" & Erl & ")"
    End Select
End Sub

Private Sub txtSearch_GotFocus()
    On Error Resume Next
    If Me.txtSearch.Value = "(Cautare)" Then
        Me.txtSearch.Value = ""
    End If
End Sub

Private Sub txtSearch_LostFocus()
    On Error Resume Next
    If Me.txtSearch.Value = "" Then
        Me.txtSearch.Value = "(Cautare)"
    End If
End Sub

Private Sub Form_Current()
    txtSearch_Change
    lstItems.SetFocus
 End Sub

'------------------------------------------------------------
' btnAddRecord_Click
'
'------------------------------------------------------------
Private Sub btnAddRecord_Click()

    On Error Resume Next
    DoCmd.GoToRecord , "", acNewRec
    If (MacroError <> 0) Then
        Beep
        MsgBox MacroError.Description, vbOKOnly, ""
    End If

End Sub


'------------------------------------------------------------
' btnDeleteRecord_Click
'
'------------------------------------------------------------
Private Sub btnDeleteRecord_Click()

    On Error Resume Next
    DoCmd.GoToControl Screen.PreviousControl.Name
    Err.Clear
    If (Not Form.NewRecord) Then
        DoCmd.RunCommand acCmdDeleteRecord
    End If
    If (Form.NewRecord And Not Form.Dirty) Then
        Beep
    End If
    If (Form.NewRecord And Form.Dirty) Then
        DoCmd.RunCommand acCmdUndo
    End If
    If (MacroError <> 0) Then
        Beep
        MsgBox MacroError.Description, vbOKOnly, ""
    End If

End Sub


'------------------------------------------------------------
' tblGrad_ID_AfterUpdate
'
'------------------------------------------------------------
Private Sub tblGrad_ID_AfterUpdate()

    If (Eval("[Forms]![accordion_mainmenu].box1![tblGrad_ID] Between 1 And 7")) Then
        Forms![accordion_mainmenu].Box1!tblCatPersonal_ID = 1
    End If
    If (Eval("[Forms]![accordion_mainmenu].box1![tblGrad_ID] Between 8 And 12")) Then
        Forms![accordion_mainmenu].Box1!tblCatPersonal_ID = 2
    End If
    If (Eval("[Forms]![accordion_mainmenu].box1![tblGrad_ID] Between 13 And 17")) Then
        Forms![accordion_mainmenu].Box1!tblCatPersonal_ID = 3
    End If
    If (Forms![accordion_mainmenu].Box1!tblGrad_ID = 18) Then
        Forms![accordion_mainmenu].Box1!tblCatPersonal_ID = 4
    End If
    If (Forms![accordion_mainmenu].Box1!tblGrad_ID = 19) Then
        Forms![accordion_mainmenu].Box1!tblCatPersonal_ID = 5
    End If

End Sub


'------------------------------------------------------------
' tblSubunitate_ID_AfterUpdate
'
'------------------------------------------------------------
Private Sub tblSubunitate_ID_AfterUpdate()

    Forms![accordion_mainmenu].Box1!MutatDin = Date
    Beep
    MsgBox "Data la care a fost mutat la alta subunitate a fost setata la data curenta. Modificati daca este necesar!", vbInformation, "Data mutarii la alta subunitate"

End Sub


'------------------------------------------------------------
' Activ_AfterUpdate
'
'------------------------------------------------------------
Private Sub Activ_AfterUpdate()

    If (Forms![accordion_mainmenu].Box1!Activ = True) Then
        Forms![accordion_mainmenu].Box1!InactivDin = Null
    End If
    If (Eval("[Forms]![accordion_mainmenu].box1![Activ]=False And [Forms]![accordion_mainmenu].box1![InactivDin] Is Null")) Then
        Beep
        MsgBox "Data la care a incetat activitatea in cadrul ISU Mures a fost setata la data curenta. Modificati daca este necesar!", vbInformation, "Data la care a incetat activitatea"
    End If
    If (Eval("[Forms]![accordion_mainmenu].box1![Activ]=False And [Forms]![accordion_mainmenu].box1![InactivDin] Is Null")) Then
        Forms![accordion_mainmenu].Box1!InactivDin = Date
    End If
    If (Eval("[Forms]![accordion_mainmenu].box1![Activ]=True And [Forms]![accordion_mainmenu].box1![ActivDin] Is Null")) Then
        Beep
        MsgBox "Data la care a inceput activitatea in cadrul ISU Mures a fost setata la data curenta. Modificati daca este necesar!", vbOKOnly, "Data la care a inceput activitatea"
    End If
    If (Eval("[Forms]![accordion_mainmenu].box1![Activ]=True And [Forms]![accordion_mainmenu].box1![ActivDin] Is Null")) Then
        Forms![accordion_mainmenu].Box1!ActivDin = Date
    End If

End Sub
 
Saying that you get an error on line 56 does us no good because you show no line numbers in your presentation. What IS line 56? What is on that line?

The error can be one of two things. Either your one of your arguments is the wrong "flavor" - ByRef vs. ByVal - OR one of your arguments is unexpectedly null or zero. A zero-length-string is unlikely to cause this particular error so I don't include it in the probable list of culprits. (A ZLS would cause other errors but not error 5.)

When we can figure out which line is causing the error and what it is trying to do, more help might be forthcoming.

Here is something to consider. A reference to Me. usually only works inside the form or report class module, not inside something contained in a module external to the form or report. If you want to reference a form/report in that way, you have to pass a reference to the form (via ByRef passage) and reference the form that way. Your explicit class module would fall into the category of "external to the actual form" that I mentioned.
 
Sorry about that.
The error occurs in the form frmPersonal vba under Private Sub txtSearch_Change() and highlights If Me.FilterOn = True Then but only when it's run from accordion_mainmenu form Private Sub btnPersRes_Click().
same code in mainmenu works with .sourceobject = "frmCursuri"
 
Upload your db with enough to show the problem and explicit instructions on how to recreate the issue.
 
If you can put a breakpoint on the offending line, you will stop execution before that line. I.e. the offending line, if properly breakpointed, is the next line to be executed. At that time you can hover the mouse over Me.FilterOn to see what its value is. If it is anything other than TRUE or FALSE (or -1 or 0), you have a reference problem.
 
is there any way i could upload the db? has 23Mb and can t post links to filesharing platforms
 

Users who are viewing this thread

Back
Top Bottom