Text box to show the results of a combo box

  • Thread starter Thread starter Lucian Sitwell
  • Start date Start date
L

Lucian Sitwell

I have made a user defined vba form in word to add the non-mailing addresses
from Outlook (if needed to the document) (since the address book dialog will
only let me paste in the mailing address in Word 2003).

I am able to load the data into an array, which displays properly in the
combo box. However, I can't get the full data from record in the combo box
to display in the text box.

Dim MyArray
Dim intIndex As Integer
intIndex = cboContact.ListIndex
txtContactAddress.Text = MyArray(intIndex)-------------this line gives
me a type mismatch.


Also, although the array is declared in the initialization of the form, I
get an error, if I don't declare it separately in the subroutine for the
text box. Is this supposed to happen? Why?

Any help would be appreciated.

Thanks

Lucian Sitwell
 
Hi Lucian,
Also, although the array is declared in the initialization of the form, I
get an error, if I don't declare it separately in the subroutine for the
text box.

maybe that´s the problem. If I understand you correctly, then you
declare MyArray in "the initialization of the form", this array contains
the data as expected, then you need the array in another subroutine, and
declare it again: So this array is new and empty.

There are two ways: You can

a) declare the array in the modul head, then it is in the scope of each
modul method,

b) spend your subroutine signature an argument. This way I would prefer.

Example:

Sub Init()
Dim MyArray() As Variant
...
' call the subroutine and pass the variable
YourSubRoutine MyArray
...
End Sub

Sub YourSubRoutine(MyArray As Variant)
...
End Sub

In addition:
Dim MyArray
This declares just a variant type variable not an array...
... MyArray(intIndex)...
.... so this must lead into an exception.
 
Back
Top