ADO recordset as data source for a subform

J

J Welsby

Please see code below. Essentially, on my form, the user pushes a button
which creates an ADO recordset and then sets this recordset as the source for
a subform on the same form

So far - for testing purposes - I have only one field (year). If the txtbox
for the number of simulations is set at 10 (for example) the loop/msgbox area
will return the numbers of 1 through 10 (thus the code appears to run ok)

All seems fine except the subform will not show the data (ie. the numbers 1
through 10). The subform shows that there is 10 records in the
recordselector, but the year field is empty

Anyone have any ideas?!
Many thanks
James


Private Sub btnRunSimulation_Click()

Dim rsADODBConnection As ADODB.Connection
Set rsADODBConnection = CurrentProject.AccessConnection

Dim rsADODB As ADODB.Recordset
Set rsADODB = New ADODB.Recordset

rsADODB.Fields.Append "Year", adInteger

rsADODB.Open

For a = 1 To txtboxNumberSimulations
rsADODB.AddNew
rsADODB("Year").Value = a
Next a

Set Me.[frmProgramme-Modelling-SimulationOutputSubForm].Form.Recordset =
rsADODB

'for testing - throw up a msgbox for each value
Do While Not rsADODB.EOF
MsgBox rsADODB("Year")
rsADODB.MoveNext
Loop

rsADODB.Close
Set rsADODB = Nothing
Set rsADODBConnection = Nothing
End Sub
 
Top