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

Access
Access
A family of Microsoft relational database management systems designed for ease of use.
400 questions
Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
881 questions
Office Management
Office Management
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Management: The act or process of organizing, handling, directing or controlling something.
2,174 questions
{count} votes

Accepted answer
  1. Albert Kallal 5,256 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. Tanay Prasad 2,130 Reputation points
    2024-06-10T12:33:16.2866667+00:00

    Hi,

    This error can appear when using VBA code to import or export data from Access database file to Access project or vice versa. It usually occurs if there are issues with arguments or parameters specified in functions, macros, queries, or other objects in the VBA code.

    1. The Access database file you’re importing should not exceed 2 GB size. Also, the records in the database file you are importing should not exceed the maximum record size limit, i.e., 4000. In such a case, you can split the Access database.
    2. Try using Compact and Repair to fix this error.
    3. Check for missing references and fix them.

    If nothing works, here's a detailed article on the same that will help you.

    Regards,

    Tanay


  2. Michael Taylor 54,811 Reputation points
    2024-06-10T21:53:35.8466667+00:00

    The value you're passing CStr(vID) isn't in the collection I'd wager. In your screenshot you show it being some sort of label. Earlier in the code when you call Add you're passing Me!Cat as the key. In order to use the index you must either pass the 1-based index or the key used in Add. My guess is they don't line up and so you get the error.

    Set a breakpoint on the failing call. Execute the code until you get to the breakpoint. Once it is hit then look at the items in your CheckItems collection in the debugger. Ensure that the value you're passing to the function matches one of the item's keys that are in the collection. I suspect it isn't and hence you are getting an error.


  3. 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

  4. 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.