Here's an example. I have a form's recordsource as a query:
Expand|Select|Wrap|Line Numbers
- SELECT * FROM StdDegReqClass WHERE StdDegReqDiscId = [Form]![Control] ORDER BY SortOrder
Expand|Select|Wrap|Line Numbers
- Dim cn As New ADODB.Connection
- Dim rs As ADODB.Recordset
- Dim lngStdDegReqDiscId As Long
- cn.Open CurrentProject.Connection
- Set rs = New ADODB.Recordset
- lngStdDegReqDiscId = Forms!f_StdDegReqDisc.txtStdDegReqDiscId
- rs.Open "SELECT * FROM StdDegReqClass WHERE StdDegReqDiscId = " & lngStdDegReqDiscId & " ORDER BY SortOrder", cn, _
- adOpenKeyset, adLockOptimistic
- Set Me.Recordset = rs
- Exit_Procedure:
- cn.Close
- Set rs = Nothing
- Exit Sub