Question

Open a new mdb from code

Asked by: LJG

I need to open a database from my VBA code.
1) Close my current database (I cant open up a new copy of Access because Im using workgroup security and dont want the user to have to put in the password again)
2) Open up a new database inside the current copy of Access.

3) I can do what I want with send keys  however I dont like it  Is there a better way.
       SendKeys "^o" & " H:\GreatApp\MyApp.mdb" & "~", False

----------------- Below is why  not any added info -----------------
OK  if you get this far you might be asking why is this crazy fool wanting to open up a database from inside VBA.  The below is the answer and as always I welcome comments on my craziness.  You dont need to read below to answer the above question  but if you must know go further.

My clients have the frontend mdb on their C drive and the data on a network.  I normally design databases that often have temp tables in the frontend mdb to put data in before I run a report.  In addition I will output Excel spreadsheets to the users local C drive.

Now that I have developed an application for a company they have their C: drives locked and dont give the users any specific space on the network.  THEY DONT WANT TO CHANGE.  So to make my application work on the network where if two users happen to run the same report that use the temp table at the same time  I need a separate mdb for each user.

The solution.

Have a database with just one object  a function that does the following.
1)      gets the users name (CurrentUser)  eg Joe Blow
2)      See if there is a frontend database in the folder with the current users name.
H:\GreatApp\Joe Blow\ MyApp.mdb
If not  Create a folder  -->  H:\GreatApp\Joe Blow
Copy the application from H:\GreatApp\MyApp.mdb  to H:\GreatApp\Joe Blow \MyApp.mdb
3)      With the current copy of Access (remember we opened it using Access workgroup security)
Close the small mdb
Open H:\GreatApp\Joe Blow \MyApp.mdb

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-06-18 at 13:39:49ID24504020
Topics

Microsoft Access Database

,

Access Coding/Macros

,

Access Architecture/Design

Participating Experts
2
Points
500
Comments
15

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. 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.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. VBA code to create empty .mdb file
    Hi all, Someone has the VBA code to create a new empty .mdb file? Regards, Tim
  2. MDE to MDB
    Hello! Can i ask if anyone know how to decrypt the MDE to MDB? Because i accedentaly deleted my MDB file.... Thanks in advance!

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: thenelsonPosted on 2009-06-18 at 13:53:20ID: 24661627

You can do that with the shell command. It can also pass the username/password.

Dim ShellRtn As Double

ShellRtn = Shell(Chr(34) & "msaccess.exe" & Chr(34) & " " & Chr(34) & Forms![Update FE]!DestinationPath & Forms![Update FE]!FileName & Chr(34), vbMaximizedFocus)
AppActivate ShellRtn

 

by: thenelsonPosted on 2009-06-18 at 14:00:41ID: 24661674

cleaned up a little:


Dim ShellRtn As Double

ShellRtn = Shell(Chr(34) & "msaccess.exe" & Chr(34) & " " & Chr(34) & PathNameofDatabaseToOpen & Chr(34), vbMaximizedFocus)

AppActivate ShellRtn

Note: Dos cannot accept apostrophes instead of Quotes so the Chr(34) is used.

 

by: LJGPosted on 2009-06-18 at 14:10:57ID: 24661754

Thanks Thenelson
The problem with the solution is that I don't want to require the user to enter the password a second time.  I would know the user name (currentuser) but would not know the password.

Thanks
LJG

 

by: thenelsonPosted on 2009-06-18 at 14:38:56ID: 24661955

> I can do what I want with send keys <

How would you pass the password with send keys?

 

by: thenelsonPosted on 2009-06-18 at 14:49:06ID: 24662040

Rereading your question:
>I normally design databases that often have temp tables in the frontend mdb to put data in before I run a report. <

Why not use a query instead of a temp table?

 

by: LJGPosted on 2009-06-18 at 14:50:01ID: 24662047

thenelson
Again, thanks for your comment.  In your situation you have one copy of Access open, then open up a second copy of Access.

In my situation, I have one copy of Access open with a mdb.  I then close the mdb and open up another mdb in the same copy using the send keys.  If you want to see how it works, the following will give you an example.

Create a new mdb
Create one form with one button

Put the following in the code behind the button.  Change the path and db name to one on your machine.

SendKeys "^o" & " H:\GreatApp\MyApp.mdb" & "~", False

When you click the button, the new database will close, and your db will open.

Hope this helps
LJG


 

by: thenelsonPosted on 2009-06-18 at 15:01:46ID: 24662142

And when you open the second db from the open file dialog, the second db doesn't ask for the password?

 

by: LJGPosted on 2009-06-18 at 15:03:50ID: 24662163


"And when you open the second db from the open file dialog, the second db doesn't ask for the password?"

Correct!

 

by: thenelsonPosted on 2009-06-18 at 15:25:48ID: 24662319

So the first db (with the sendkeys) was opened with a password? Or is your second db capturing the password from Windows? If the later, it will work the same with the shell command.  You can take a look at http://www.thenelson.name, Updated Front End.  I use this to automatically update the FE. It works fine when the second db is secured with ULS.

 

by: LJGPosted on 2009-06-18 at 15:42:31ID: 24662420

Thenelson

I'm using workgroup security - So they need a name and password to login.  We don't use the Windows password - Just Access's workgroup.

 

by: LPurvisPosted on 2009-06-19 at 07:44:12ID: 24666803

There's the example here for passing UN and PW in the command line (I don't love that particularly)
http://support.microsoft.com/kb/147816
(but I like it better than http://support.microsoft.com/kb/q192919/)

The other method that occurs I could have sworn also had an MS article describing, but I don't seem to be able to find it...
A similar method is mentioned elsewhere though - so an earlier thread here at EE will have to do for possible adapting. :-s
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_10223790.html#2204746

 

by: LJGPosted on 2009-06-19 at 15:33:47ID: 24670639

LPurvis
Thanks for the information.  The problem is taht all 3 of your solutions require the user to give the password OR to know the password and put it in code.  There is no problem with knowing the user's name (currentuser) but the password is something I don't want to have the user to have to put in a second time.

thanks for the work
LJG



 

by: LJGPosted on 2009-06-26 at 07:20:04ID: 24721196

Thanks all for your effort - The only way I found to do this is with send keys - see attached code.

Note: I WOULD NEVER RECOMMEND DOING THIS!  The only reason I am doing this is because the company wanted to lock down the C drive and I need to us temporary tables in the inside the database and also output Excel spread sheets.  This will allow everyone to have their own copy on the network.

So if you read my first post and read the above and still want to know how to do it - keep reading.  If you find a better way to do it, please post it to this question and I would love to get rid of the send keys.

1) We are using workgroup security - it doesn't work unless you are using workgroup security
2) I put a copy of the frontend db in the same folder as the below database
3) I have a database called OpenDB.mdb with only two objects a macro and one function
       *  With an AutoExec macro that call the below code --> Auto_Exec()
       *  If you go into the code --> Auto_Exec() and change the below line to your front end db (note must be in the same folder as OpenDB.mdb)- it should work for you.

Hope this helps someone
                     Dim strDatabaseName As String: strDatabaseName = "MYApp.mdb"

Public Function Auto_Exec()
 
'----
' Purpose:  Start UnityTPM_App.mdb in the user's Folder
 
' Example:  Auto_Exec()
 
'----
'Hide Database Window
    DoCmd.RunCommand acCmdWindowHide
 
'Turn System Toolbars off
    Application.SetOption "Built-In Toolbars Available", False
 
 
'Turn off Menu
        Application.MenuBar = "NoMenu"
    
'Wait for system to catch up
    Dim i As Integer
    For i = 1 To 10
        DoEvents
    Next i
'----
 
Dim strMain_Path As String
Dim strTemp As String
Dim strNew_Path As String
Dim strDatabaseName As String: strDatabaseName = "MYApp.mdb"
 
Dim strMain_Path_DB As String
Dim strNew_Path_DB As String
 
'----
On Error GoTo HandleError
'If Programming_Mode Then On Error GoTo 0
'--------
 
 
'Get the Current Path
    strMain_Path = CurrentDb.Name
    strTemp = Dir(strMain_Path)
    strMain_Path = Left(strMain_Path, Len(strMain_Path) - Len(strTemp))
    
'Path and database that we copy if we need to
    strMain_Path_DB = strMain_Path & strDatabaseName
        
        
'Add current User to the path we start from
    strNew_Path = strMain_Path & CurrentUser & "\"
    strNew_Path_DB = strNew_Path & strDatabaseName
   
'If the file doesn't exist copy it
    On Error Resume Next
    If FileLen(strNew_Path_DB) = 0 Then
        MkDir strNew_Path
        FileCopy strMain_Path_DB, strNew_Path_DB
    End If
 
'Open the file - this will automatically close this database
    SendKeys "^o" & strNew_Path_DB & "~", False
'--------
 
ProcedureDone:
    Exit Function
 
HandleError:
    Select Case Err.Number
        Case Else
            MsgBox Err.Description & vbCrLf & "in: mod_Local.Auto_Exec" & vbCrLf & CurrentDb.Name
    End Select
    Resume ProcedureDone
    
End Function
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:

Select allOpen in new window

 

by: LJGPosted on 2009-06-26 at 07:21:51ID: 31594125

Thanks for the help, but I decided to stay with my Send Key solution - See below.
LJG

 

by: thenelsonPosted on 2009-06-26 at 07:25:51ID: 24721246

You're welcome.  Glad to help and thank you very much for the points with "A" grade!

Happy Computing!

Nelson

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...