By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,784 Members | 1,188 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,784 IT Pros & Developers. It's quick & easy.

Populate An Unbound Form with Recordset

100+
P: 194
Hello Everybody,

Please tell me is there any way to populate an unbound form of MS Access 2002 with Recordset of an MS Access 2002 external database??

if yes then how???

I dont wana link tables/queries what i want is to hold all data in recordset and then display it into the form like continuous forms.

thank u.
Nov 22 '07 #1
Share this Question
Share on Google+
2 Replies


FishVal
Expert 2.5K+
P: 2,653
Hi, where.

You may try to use Form.Recordset property.
The following code bind an unbound form to table [t1] located in the same db.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     Set Me.Recordset = CurrentDb.OpenRecordset("SELECT * FROM t1;")
  3. End Sub
  4.  
P.S. Sure, forms controls are expected to have right values in ControlSourcce property.
Nov 22 '07 #2

ADezii
Expert 5K+
P: 8,675
Hello Everybody,

Please tell me is there any way to populate an unbound form of MS Access 2002 with Recordset of an MS Access 2002 external database??

if yes then how???

I dont wana link tables/queries what i want is to hold all data in recordset and then display it into the form like continuous forms.

thank u.
Let's assume you wish to populate an Unbound Access Form consisting of three Unbound Text Boxes named txtFirstName, txtLastName, and txtBirthDate. Furthermore, the mechanism with which you wish to populate this Form is via a Recordset created on an External Database. In this scenario, the External Database is Northwind.mdb residing in the C:\Test\ Directory. We will use the Employees Table as the source of the Recordset and populate our Unbound Access Form and Text Boxes with 3 Fields from this Recordset. Follow these 3 simple steps:
  1. Place the following Declarations in the Form's Code Module (Declarations Section):
    Expand|Select|Wrap|Line Numbers
    1. Dim wrkJet As Workspace
    2. Dim dbsNorthwind As DAO.Database, rstNorthWind As DAO.Recordset
  2. Copy and Paste the following code to the Open() Event of the Form:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Open(Cancel As Integer)
    2. 'Create Microsoft Jet Workspace object.
    3. Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
    4.  
    5. 'Open Database object from saved Microsoft Jet database for exclusive use
    6. Set dbsNorthwind = wrkJet.OpenDatabase("C:\Test\Northwind.mdb", True)
    7.  
    8. Set rstNorthWind = dbsNorthwind.OpenRecordset("Employees", dbOpenDynaset)
    9.  
    10. Set Me.Recordset = rstNorthWind
    11.  
    12. Me![txtFirstName].ControlSource = "FirstName"
    13. Me![txtLastName].ControlSource = "LastName"
    14. Me![txtBirthDate].ControlSource = "BirthDate"
    15. End Sub
  3. Place the following code in the Close() Event of the Form:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Close()
    2.   rstNorthWind.Close
    3.   Set rstNorthWind = Nothing
    4. End Sub
  4. This code has been tested and is fully operational, let me know how you make out.
Nov 22 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.