• Run Time Error (Access 97)

    Author
    Topic
    #412634

    I am trying to change a selection in a combo box and I am getting a message which states, “Run-time error ‘5’: Invalid procedure call or arguement, and then access locks up and closes.

    My line of code is: cmbPrincipal.Value = Mid(cmbPrincipal.Value, (comma + 2), 1) & “. ” & Left(cmbPrincipal.Value, (comma – 1))
    Can anyone help me with the problem?
    Any help is appreciated.
    Thanks,
    Nick

    Viewing 1 reply thread
    Author
    Replies
    • #904096

      The code itself is valid, so it must be something in the values being processed. Set a breakpoint on the line of code (click in it and press F9). When you run the code, it will pause at the breakpoint. You can inspect the value of variables and properties by hovering the mouse over them.
      – What is the value of cmbPrincipal.Value ?
      – What is the value of comma ?

      • #904104

        The comma is equal to zero, and the cmbPrincipal.value is equal to the new value I am selecting from the combo box.

        Thanks,
        Nick

        • #904112

          If comma is 0, (comma – 1) is negative, so Left(cmbPrincipal.Value, (comma – 1)) will cause an error: you cannot extract -1 characters from a string.

          You haven’t explained what the variable comma is, but I suppose you use InStr to find the position of the first comma in the value of the combo box. If there is no comma, InStr returns 0. So you should test that the value of the variable comma is positive:

          comma = InStr(cmbPrincipal.Value, “,”)
          If comma > 0 Then
          cmbPrincipal.Value = Mid(cmbPrincipal.Value, (comma + 2), 1) & “. ” & Left(cmbPrincipal.Value, (comma – 1))
          End If

          • #904118

            Here is the section of code:

            Private Sub cmbPrincipal_AfterUpdate()
            Dim searchstring, searchchar As String
            Dim Length, comma As Integer

            searchstring = cmbPrincipal.Value
            searchchar = “,”
            Length = Len(cmbPrincipal.Value)
            comma = InStr(searchstring, searchchar)
            cmbPrincipal.Value = Mid(cmbPrincipal.Value, (comma + 2), 1) & “. ” & Left(cmbPrincipal.Value, (comma – 1))
            End Sub

            When the form is opened and a new value is picked from the combo box, I get the error. However, when I run the database from a server, it works fine. When I run the database from my workstation, I get the error.

            Thanks,
            Nick

            • #904122

              The variable Length isn’t used at all in this code, but that is not the cause of the error. Insert the test I suggested in my reply.

            • #904123

              The variable Length isn’t used at all in this code, but that is not the cause of the error. Insert the test I suggested in my reply.

          • #904119

            Here is the section of code:

            Private Sub cmbPrincipal_AfterUpdate()
            Dim searchstring, searchchar As String
            Dim Length, comma As Integer

            searchstring = cmbPrincipal.Value
            searchchar = “,”
            Length = Len(cmbPrincipal.Value)
            comma = InStr(searchstring, searchchar)
            cmbPrincipal.Value = Mid(cmbPrincipal.Value, (comma + 2), 1) & “. ” & Left(cmbPrincipal.Value, (comma – 1))
            End Sub

            When the form is opened and a new value is picked from the combo box, I get the error. However, when I run the database from a server, it works fine. When I run the database from my workstation, I get the error.

            Thanks,
            Nick

        • #904113

          If comma is 0, (comma – 1) is negative, so Left(cmbPrincipal.Value, (comma – 1)) will cause an error: you cannot extract -1 characters from a string.

          You haven’t explained what the variable comma is, but I suppose you use InStr to find the position of the first comma in the value of the combo box. If there is no comma, InStr returns 0. So you should test that the value of the variable comma is positive:

          comma = InStr(cmbPrincipal.Value, “,”)
          If comma > 0 Then
          cmbPrincipal.Value = Mid(cmbPrincipal.Value, (comma + 2), 1) & “. ” & Left(cmbPrincipal.Value, (comma – 1))
          End If

      • #904105

        The comma is equal to zero, and the cmbPrincipal.value is equal to the new value I am selecting from the combo box.

        Thanks,
        Nick

    • #904097

      The code itself is valid, so it must be something in the values being processed. Set a breakpoint on the line of code (click in it and press F9). When you run the code, it will pause at the breakpoint. You can inspect the value of variables and properties by hovering the mouse over them.
      – What is the value of cmbPrincipal.Value ?
      – What is the value of comma ?

    Viewing 1 reply thread
    Reply To: Run Time Error (Access 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: