Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > Opening Database 2 from within Database1


Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2002, 07:39 AM
Deco
Guest
 
Posts: n/a
Question Opening Database 2 from within Database1


I've got a module in database 2 which runs when the database 2 is opened. When it has finished the database closes down. What I would like to be able to do is to open database 2 from database 1 to run this module, close database 2 and keep database 1 open. I would appreciate if one of you experts out there could advise me if this is possible and if so how do I do it.

Many thanks
Reply With Quote
  #2  
Old 03-14-2002, 08:20 AM
Thinker Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

I must assume you are referring to Access, and you are using VBA
for the programming. You would have to use automation to open
a second instance of Access with database2 loaded. I also guess
that if the sub runs automatically when opened normally, it will
under this method also.
__________________
Posting Guidelines
Reply With Quote
  #3  
Old 03-15-2002, 01:54 AM
Deco
Guest
 
Posts: n/a
Default

Yes I'm using VBA within Access. I've tried what you said (see code below) and when I step through the procedure it appears to be working but nothing actually happens.
Any ideas?????

Cheers


Private Sub Command0_Click()
Dim dbs As Database
Dim dbImport As Database
Dim strdb As String
Dim wrkJet As Workspace

Set dbs = CurrentDb
Set wrkJet = DBEngine.Workspaces(0)

MsgBox "Opening"

strdb = "G:\reinledg\Midnight\697LPC\LPCCashImport.mdb"

Set dbImport = wrkJet.OpenDatabase(strdb)

End Sub
Reply With Quote
  #4  
Old 03-15-2002, 07:00 AM
Thinker Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

You aren't opening a second copy of Access with automation, you
are just opening a database object with DAO. You would have to
use the CreateObject() function to start a new instance of Access.
__________________
Posting Guidelines
Reply With Quote
  #5  
Old 05-20-2002, 02:46 PM
ooosadface
Guest
 
Posts: n/a
Thumbs up

Quote:
Originally posted by Thinker
You aren't opening a second copy of Access with automation, you
are just opening a database object with DAO. You would have to
use the CreateObject() function to start a new instance of Access.
Yes, thank you...
I'd been looking for this for a couple of days now. I had been opening other databases from a .bat file. Where I work, we have slowly (somehow) started using three different OSes (98, NT and 2000) and the minor differences in the .bat file were annoying me. I now have is switched to VB(A) and it is due to Thinker pointing out the CreateObject() function to start my other instance of Access. From there I loaded my database into it with the GetObject() function and all is well. So much easier than the .bat file.

Thanks for your help Thinker (even though you didn't know you were helping me!)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->