G
Guest
Greetings,
I have the following code in Access 2000 and have a question in regards to
arrays. I was wondering if I can declare a variable array (without
specifying the number of elements ahead of time)? The reason I ask is that
the size of the array will vary depending upon the number of elements a user
selects in a list box. So far, I have been unable to get this to work. I
have tried "Dim strArray() as String", but I receive the error message
"Subscript out of range" when I attempt to assign a value to the individual
array element. Is there something obvious I am missing here? My current
code is below.
Thanks in advance!
Private Sub cmdAdd_Click()
Dim db As DAO.Database
Dim i As Long
Dim j As Long
Dim rs As DAO.Recordset
Dim ctlSource As Control
Dim strArray() As String
Dim strItem As String
Dim lngCurrentRow As Long
Set ctlSource = Me!lstBranchCodes
i = 0
'// Loop through the list box to obtain each item that was selected.
For lngCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(lngCurrentRow) Then
strItem = ctlSource.Column(0, lngCurrentRow)
'// "Subscript out of range" occurs here.
strArray(i) = strItem
i = i + 1
End If
Next lngCurrentRow
...
...
I have the following code in Access 2000 and have a question in regards to
arrays. I was wondering if I can declare a variable array (without
specifying the number of elements ahead of time)? The reason I ask is that
the size of the array will vary depending upon the number of elements a user
selects in a list box. So far, I have been unable to get this to work. I
have tried "Dim strArray() as String", but I receive the error message
"Subscript out of range" when I attempt to assign a value to the individual
array element. Is there something obvious I am missing here? My current
code is below.
Thanks in advance!
Private Sub cmdAdd_Click()
Dim db As DAO.Database
Dim i As Long
Dim j As Long
Dim rs As DAO.Recordset
Dim ctlSource As Control
Dim strArray() As String
Dim strItem As String
Dim lngCurrentRow As Long
Set ctlSource = Me!lstBranchCodes
i = 0
'// Loop through the list box to obtain each item that was selected.
For lngCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(lngCurrentRow) Then
strItem = ctlSource.Column(0, lngCurrentRow)
'// "Subscript out of range" occurs here.
strArray(i) = strItem
i = i + 1
End If
Next lngCurrentRow
...
...