By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,475 Members | 1,372 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,475 IT Pros & Developers. It's quick & easy.

Using ".OpenCurrentDatabase" in VB .net to open an MS Access DB

P: n/a
Hello,
when I execute the code below I get the usual access message:

SECURITY WARNING----------------------------------

Opening "<filepath & name.mdb>"

The file may not be safe if it contains code that was intended
to harm your computer.
Do you want to cancel the operation?

CANCEL OPEN MORE INFO

---------------------------------------------------

Private Sub OpenDB(ByVal strMDBFullPath as string)

Dim appDatabase As Access.Application

appDatabase = New Access.Application()
appDatabase.OpenCurrentDatabase(p_strMDBFullPath, True)

....

End Sub

How can I detect if the user presses the CANCEl button? With the code
above if the user presses the CANCEl button the code throws an exception
on the line "appDatabase.OpenCurrentDatabase(p_strMDBFullP ath, True)".

The code is VB .net and the database is 2003 but could be 97, 2000 etc.

Thanks in advance

Paul M.

Jan 7 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a


I wonder what you are trying to do

do you want to retrieve data from the access database ?

if so this is not the way ( you propbaly have set a reference to the office
lib )

normally you access a access database by the oledb namespace

regards

Michel Posseth [MCP]

"Paul M" <pa**@nospam.co.uk> wrote in message
news:dp**********@newsg3.svr.pol.co.uk...
Hello,
when I execute the code below I get the usual access message:

SECURITY WARNING----------------------------------

Opening "<filepath & name.mdb>"

The file may not be safe if it contains code that was intended
to harm your computer.
Do you want to cancel the operation?

CANCEL OPEN MORE INFO

---------------------------------------------------

Private Sub OpenDB(ByVal strMDBFullPath as string)

Dim appDatabase As Access.Application

appDatabase = New Access.Application()
appDatabase.OpenCurrentDatabase(p_strMDBFullPath, True)

...

End Sub

How can I detect if the user presses the CANCEl button? With the code
above if the user presses the CANCEl button the code throws an exception
on the line "appDatabase.OpenCurrentDatabase(p_strMDBFullP ath, True)".

The code is VB .net and the database is 2003 but could be 97, 2000 etc.

Thanks in advance

Paul M.

Jan 7 '06 #2

P: n/a
Hello Paul,

You have cross-posted to a lot of groups.

Your answer is in your question. When the user presses Cancel you get an
error, so trap the error and use it.

Here's what you can do.

Try
Your Code
Catch ex as exception
do something with the exception
End Try

That should solve it for you Paul

Cyril Gupta
Jan 7 '06 #3

P: n/a
TC
No to answer your question, but: do you really want to open that
database /in the Access user interface/? Or do you just want to open
it "behind the scenes", so you can get at the data within it?

If the latter, then, you need OpenDatabase - not OpenCurrentDatabase.

HTH,
TC [MVP Access]

Jan 8 '06 #4

P: n/a
Cyril Gupta wrote:
Hello Paul,

You have cross-posted to a lot of groups.

Your answer is in your question. When the user presses Cancel you get an
error, so trap the error and use it.

Here's what you can do.

Try
Your Code
Catch ex as exception
do something with the exception
End Try

That should solve it for you Paul

Cyril Gupta

Hello Cyril,
thanks for that, I had already considered that but just wanted a more
elegegant way of doing ie testing a return value, that sort of thing.

Thanks
Paul
Jan 13 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.