Assigning Recordsets Dynamically to a form
Sub runFormNY()
Dim con As ADODB.Connection
Dim myRecordset As Recordset
Dim strFrmNm As String
Set myRecordset = New ADODB.Recordset
myRecordset.CursorType = adOpenKeyset
myRecordset.LockType = adLockOptimistic
Set con = New ADODB.Connection
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\mydb.mdb;"
myRecordset.Open "SELECT * FROM Employees", con
strFrmNm = "frmCustomer"
DoCmd.OpenForm strFrmNm
Set Application.Forms(strFrmNm).Recordset = myRecordset
myRecordset.Close
con.Close
Set myRecordset = Nothing
Set con = Nothing
End Sub
Related examples in the same category