Invalid procedure call or argument error

Lopez, Ahiezer 236 Reputation points
2024-06-04T21:28:57.5766667+00:00

When pressing a command button the code below is executed, and it results in an error as seen in the picture. In addition, I seem to be the only user with this issue. My coworkers don't mention having this issue. I never had this issue until about a month ago.

Cmd button Code: Private Sub cmdCheck_Click()

On Error GoTo Err_Close_Jobs

Dim i As Integer

' check in our list

If MySel(Me!Cat) Then

' already in list - remove

CheckItems.Remove CStr(Me!Cat)

Else

' not in the list - add it

CheckItems.Add Me!Cat.Value, CStr(Me!Cat)

' Debug.Print CheckItems

End If

Me.ckSel.Requery

Exit_Close_Jobs:

Exit Sub

Err_Close_Jobs:

MsgBox Err.Number & "/" & Err.Description

Resume Exit_Close_Jobs

End Sub

Code:

Public CheckItems As New Collection

Private Sub cmdCheck_Click()

On Error GoTo Err_Close_Jobs

Dim i As Integer

' check in our list

If MySel(Me!Cat) Then

' already in list - remove

CheckItems.Remove CStr(Me!Cat)

Else

' not in the list - add it

CheckItems.Add Me!Cat.Value, CStr(Me!Cat)

' Debug.Print CheckItems

End If

Me.ckSel.Requery

Exit_Close_Jobs:

Exit Sub

Err_Close_Jobs:

MsgBox Err.Number & "/" & Err.Description

Resume Exit_Close_Jobs

End Sub

User's image

Image

Microsoft 365 and Office | Access | Development
Microsoft 365 and Office | Install, redeem, activate | For business | Windows
Microsoft 365 and Office | Access | For business | Windows
{count} votes

Accepted answer
  1. Albert Kallal 5,586 Reputation points
    2024-06-12T17:30:57.27+00:00

    Check items is a collection. If the item is not in the collection, then a error occurs. You need to change the break mode settings in VBA. Tools->options, general tab, and choose the option "Break on unhandled Errors"

    VBA collections don't have a built in function to test for existence in the collection, so error trapping is a workaround for this feature.


5 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.