Access 2010 vba to open an ADODB recordset on form load/open
Posted on 2013-09-17
I have a form whose datasource is set to a query that populates the form (this works fine).
I need to perform some calculations at various stages throughout the form once the form has been opened so I am trying to open an ADODB recordset on the OnLoad event that pulls the values required for the calculations (from tblRates) and makes them available throughout the form as and when required.
I have put the following code in the OnLoad Event of the form but I am getting a "Compile Error: User-Defined type not defined " on line 1 when i open the form.
Any suggestions please?
Dim RS As ADODB.Recordset
Set RS = ADODB.Recordset
Dim strRate_Pens As Single ' Dim strRate_Pens As String
RS.Open "SELECT Rate_Pens FROM tblRates", CurrentProject.Connection, adOpenStatic
strRate_Pens = RS!Rate_Pens
Set RS = Nothing