Hello
I'm fairly new to using VBA so hopefully someone out there can advise me on what is wrong with my code (below).
I have been selecting using a query and want to place the results into an array variable, it is possible that there may be between 1 and 20 results.
I would then like to place this array variable within code to send as an email using vba showing all the results found and hopefully(!) stored in the array.
I have got the following code which seems to run the query fine but when I place the Finalstring variable, within my email code produces 'Subscript out of range' error.
Any help would be greatly appreciated.
Many thanks
Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click
Dim rst As ADODB.Recordset
Dim vary As Variant
Dim RecordCount As Integer
Dim FinalString As String
Set rst = New ADODB.Recordset
rst.Open "Select urn from DeletedBAR", CurrentProject.Connection, adOpenStatic, adLockReadOnly
rst.MoveFirst
vary = rst.GetRows(rst.recordcount)
FinalString = vary(0, rst.RecordCount)
I'm fairly new to using VBA so hopefully someone out there can advise me on what is wrong with my code (below).
I have been selecting using a query and want to place the results into an array variable, it is possible that there may be between 1 and 20 results.
I would then like to place this array variable within code to send as an email using vba showing all the results found and hopefully(!) stored in the array.
I have got the following code which seems to run the query fine but when I place the Finalstring variable, within my email code produces 'Subscript out of range' error.
Any help would be greatly appreciated.
Many thanks
Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click
Dim rst As ADODB.Recordset
Dim vary As Variant
Dim RecordCount As Integer
Dim FinalString As String
Set rst = New ADODB.Recordset
rst.Open "Select urn from DeletedBAR", CurrentProject.Connection, adOpenStatic, adLockReadOnly
rst.MoveFirst
vary = rst.GetRows(rst.recordcount)
FinalString = vary(0, rst.RecordCount)