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!

Avoiding the MS Access (2002) password prompt 1

Status
Not open for further replies.

DayLaborer

Programmer
Joined
Jan 3, 2006
Messages
347
Location
US
Before I ask my question, let me state that I have read the KB article at
I am iterating and attempting to open many Access databases programatically with VB.NET using
[tt] oAccess.OpenCurrentDatabase(FilePath)[/tt]

What I want to happen is if there is no password on that Access DB - it should open. Some databases will have passwords - none of which I will have. If there is a password, I want my code to detect that and move on to the next one - without getting stopped by the password prompt...

(No, this is not illegal/immoral - I'm doing a legit project at work. :-))

Please help...

Thanks!
Eliezer
 
A Try...Catch should work for that. Put the open statement in the Try, then have it catch the error. I'm assuming you'll want a log of which databases have security and which don't, so you could add a FSO.WriteLine item in the Try for success(no password) and one in Catch(password).

I'm not sure what the exception is that you'd get when it looks for a password, but a breakpoint will let you get that info.
 
I decided to do something similar:
Code:
Dim cnTest As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & FilePath)
cnTest.Open()
cnTest.Close()
If that blows up, it's password protected. :-)

Another related question, if I may...

One of the Access DBs has some kind of macro that runs when it's opened. Unfortunately, the macro blows up and displays a warning "You can't find or replace now". How can I supress that? Is there anything I can set on my object:
Code:
Dim oAccess = New Access.Application
???

Thanks again!
Eliezer
 
...or is it possible to have the "Access.Application" object not run any macros upon opening? That would be even better...

Eliezer
 
Honestly, I've never ran into that before. Typically, I know the database that I'm connecting to and just insure that there's no macros set for startup that require specific information to be passed. When opening a database for connection the macros are on auto run. There are keystrokes that can prevent the macros from running if you use Access, but since you're using an ADO connection theres no way to pass that through to the macro.

If you use the Try Catch block you can specifically catch that error (once you get the error type).
 
MacLeod,

I'm interested in what you wrote:
If you use the Try Catch block you can specifically catch that error (once you get the error type).

I feel like this has become somewhat of a new topic, so I'm starting a new thread "Catching a Access error in VB.NET"

Thanks!
Eliezer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top