Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Ms Access vba script using arrays. 1

Status
Not open for further replies.

feversham

Programmer
Jun 14, 2006
2
GB
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)
 
Hi JerryKlmns

Thanks for your prompt reply,

That seems to have solved the subscript problem, only I am now only getting the first record placed in my email, any ideas as to what is missing to pull in all the records

Regards
 
Why not simply use the GetString method ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top