One Varible Changing another RRS feed

  • Question

  • I am writing an Access (2007) VBA program on a Windows 7 machine that the end results creates a Letter of Approval for producst. The problem I’m having is that we I set one variable it will reset another one that has no direct relationship.

    To help explain the problem I have copied some of the code and I’ll try to explain it.

    In one procedure the multi_models array is filled will the needed information. This array is redim to be the number of possible models on a given date by 8(information needed).

    The section below is used to make a list of models that can be added to the same line. By the way, all of the variables and array are defined in a separate module since they might be used in many places.

    This section of code is in a procedure called get_models:

    If a_count > 1 Then  ‘a_count the number of possibly models

            If multi_models(a_count, 0) = multi_models(a_count - 1, 0) Then

                temp_OEM_Models = temp_OEM_Models & ", " & multi_models(a_count, 1) '& ", "

            End If

        ElseIf a_count = 1 Then

            temp_OEM_Models = multi_models(a_count, 1) & ", "

        End If

    The following commands just moves the variable to another (both are strings) and calls the routine to set the line length and are in the same module as above..

    Models = temp_OEM_Models


    Call set_line_length(Models)

    Here is where the call is going to:

    Public Sub set_line_length(STB_MODEL_NAME As String) 

    Now here is the problem when I do the following command (needed to reset the variable STB_MODEL_NAME to the rest of the models that were not placed on a line.

      STB_MODEL_NAME = temp2 'causes a weird problem where multi_models(x, 2) gets deleted.

    When the above command runs it will delete what is in multi_models(x, 2).  Multi_models(x,1) contains the models and multi_models(x, 2) contains the date approved.

    I have figured out a work around but for the life of me I can’t explain why this is happening.  Does anyone have a clue?

    Monday, September 19, 2011 8:23 PM