Link to home
Start Free TrialLog in
Avatar of alevin16
alevin16Flag for United States of America

asked on

Automatically connecting a network drive (and disconnecting) via Access 2013 VBA

Hello All

I have an Access program where the front end will reside on everyone's machine and the back end is on a server in the building.  To get to the back end the person would have to connect to the server and supply an id and password.

I created a .bat file that they can run just before opening the Access database but I was wondering if there was a way to put that net use connection string into the Access code itself.  When I try running the Access database without connecting to the network drive I get an error, but the error comes up so quickly (before even the main form pops up) that I did not know if there was some way to do the connecting first.

Any ideas?

Thanks!
Avatar of Surone1
Surone1
Flag of Suriname image

is the main form bound to a linked table or does it try to access a linked table?
if so you may want to use an unbound form as a main form, and do the connecting there.  using a shell comand
http://dmcritchie.mvps.org/excel/shell.htm
and after that open the "old" main form.
i'm not 100%  sure if this will work, but if it doesn't there may be another way  way to  try this.
Avatar of Jim Dettman (EE MVE)
<<To get to the back end the person would have to connect to the server and supply an id and password.>>

 That's a bit odd...usually a windows log in will take care of things fine.

<<I created a .bat file that they can run just before opening the Access database but I was wondering if there was a way to put that net use connection string into the Access code itself. >>

 As long as you don't try and get to the back end tables, yes you'd be fine.  I'm sure there's a windows API as well that could be called in place of the .BAT.  Would have to dig for that though.

  As nick said, make sure your not trying to touch the backend before you execute the batch file.  If you can't do that easily within your current app, consider a small "Launcher" app that executes the batch file, then calls the main app.

Jim.
Avatar of alevin16

ASKER

Hey Jim,

Is the launcher app something I could find online or is that something I would create in Access?  Basically the main form is unbound.  I have the backend tables linked via the ODBC connection.  I guess the program is trying to refresh the connections before it does anything else.

I like the Launcher app idea.  Please get back to me with any more info you have.  I will look online in the mean time.
Andy
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Jim,

The batch file worked.  Thanks!

Andy