Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Jun 2004
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Run Time Error (Access 97)

    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

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Run Time Error (Access 97)

    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 ?

  3. #3
    2 Star Lounger
    Join Date
    Jun 2004
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run Time Error (Access 97)

    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

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Run Time Error (Access 97)

    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

  5. #5
    2 Star Lounger
    Join Date
    Jun 2004
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run Time Error (Access 97)

    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

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Run Time Error (Access 97)

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •