Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bound Form Teaser! 2

Status
Not open for further replies.

rookery

Programmer
Apr 4, 2002
384
GB
Is it possible to open a database using:

Set MyDb = DBEngine(0).OpenDatabase("DemoData")

and then set the RecordSource of a Form to a Table within this database, effectively binding it to that Table?

Using an unbound form with 3 fields on it, I was able to open a database (as above) and then create a RecordSet based on a Table within that database. I then put the values of the fields into the relevant fields.

I want to achieve the same result through Binding the Form to a Table which is contained within a .mdb that has been opened using the above code. Is this possible?

Phew!
 
Why not just link to the table in the other database? That way, you don't have to worry about opening it, and you can use it as a source for a bound form. You can update, insert, and delete data in the table as though it were in your primary database. Why recreate the wheel when Access provides a simple way to do what you want to do?

Access ROCKS!

Kevin R. Sherman
 
Thanks Kev for your reply. The reason I dont just link to another table is because I have a number of back-end databases all very similar in structure i.e. the tables are the same in design and even name. I dont really want to have to trawl thru each one individually adding 1,2,3 etc to the end of table names so as to differentiate them from one another.

This would also imply that the front-end .mdb would house numerous linked tables which I'm trying to avoid.

 
Use an 'IN' clause in your select statement associated with the recordsource to direct you to the tables in another Access database.

for example: SELECT * FROM tblYourTableName
IN 'C:\YourPath\YourDatabase.mdb';

This way, you do not need to link in the tables into your database.

One way to use this approach is to set up a global variable with the path and db name string, and then to assign this to a recordsource property of the object you're opening (eg. form or report) on the associated onopen event.

This approach may give you a problem with dragging and dropping fields onto a form/report, so its as well to eithor set up queries or links whilst you're developing the form or report objects.

And no, you dont need any 'Set MyDb = DBEngine(0).OpenDatabase("DemoData")' type statement for this approach.

Hope this helps,
Steve
 
Steve you are a diamond! Works a treat. Have a star!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top