troubleshooting Question

Using RecordSource vs Recordset in Forms

Avatar of shambalad
shambaladFlag for United States of America asked on
Microsoft Access
2 Comments2 Solutions3131 ViewsLast Modified:
Below are two procedures for defining the data associated with a form. One uses the form's RecordSource property, the other uses the form's Recordset property.
Are there any distinct advantages to using one procedure over the other? What are the implications of changing a form so that the data is defined using the recordset property as opposed to the recordsource property?
I am in the midst of writing an application (2007 - accdb) where the tables and queries may reside in either the local or a remote database (I am not using logical files). In order to accomplish this, I need to control the opening of the recordsets, which, in turn, means that I find myself switching from using the form recordsource property to the form recordset property.
I'm just trying to make sure I don't engender some unexpected consequences in making this modification.
Private Sub UseRecordSource()
   Dim strSQL As String
   strSQL = "SELECT A,B,C From Table1 WHERE A = '10' ORDER BY B"
   Me.RecordSource = strSQL
End Sub

Private Sub UseRecordSet()
   Dim rst As DAO.Recordset
   Dim db As DAO.Recordset
   Dim strSQL As String
   strSQL = "SELECT A,B,C From Table1 WHERE A = '10' ORDER BY B"
   Set db = CurrentDb
   Set rst = db.OpenRecordset(strSQL)
   Set Me.Recordset = rst
End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros