473,320 Members | 2,054 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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
5 4638
"Paul M" <pa**@nospam.co.uk> schrieb
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)".

Catch the exception. See the 'Try' and 'catch' keywords.
Armin

Jan 7 '06 #2


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 #3
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 #4
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 #5
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 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: JED | last post by:
I have an opportunity to work on a web based project using Access. However, there has been a suggestion that MySQL might be a better alternative. The project is actually a small project (less than...
5
by: dananrg | last post by:
I've created a small company database where the tables reside in a SQL Server database. I'm using Access 2000 forms for a front end. I've got a System DSN set-up to SQL Server and am using links...
6
by: Clément Collin | last post by:
I working on a GIS project, with Access link which just need a little routine in VBA, but I haven't knowledges in VBA language. It's very simple, and it looks like that in a TPascal way : .......
3
by: bill mahoney | last post by:
Hello, I am using access 2000 and I am trying to email a csv file. I have only used the docmd.sendobject command but you can only email objects that are within the access database ( as far as I...
4
by: hendafe | last post by:
I have a problem of removing '/' in Access. I have a field with this record BD/02/1234. I want to automatically remove the '/' and save it in a new field record for another purpose. Presently...
6
by: Serious_Practitioner | last post by:
Good day all, and thank you in advance for your help. No - MANY thanks in advance for your help - I know nothing about using databases on Web servers. I am about to discuss a project with a...
0
by: meyvn77 | last post by:
Hello, I wrote an .ADP application in Access 2002 and delivered it to the client. They are not due for an upgrade till January and are running Access 2000. They would like to use the...
4
by: Bugs | last post by:
Hi everyone. I am trying to open a database which works fine using Access 2003, but when trying to open it on another PC that has Access 2002 I get the following error "This database is...
1
by: klaydze | last post by:
hi, i don't know how to start my code in uploading an image using open file dialog control. any one who can help me? i want to view the picture that i want to upload using open file dialog and show...
3
by: Bruce | last post by:
I have a number of Access 2000 format databases on a Windows 2003 server. For some reason I can no longer compact these databases directly on the server using Access 2003. Access 2000 seems to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.