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

VB.NET

    Next

  • 1. Whidbey - Extending "My."
    Hi, I want to extend the My (like My.Application, My.Forms and so on) with some DataBase methods. If I write this.... Namespace My Public Class DataBase End Class End Namespace Then My.DataBase will (logically) show in My as a Class. All other methods in My is listed as Properties. How can I make My.DataBase as a property instead of a class? Thanks!! M O J O
  • 2. Form_Load event.
    In vb6, you could do all the resizing of the form (and its constituent controls) in the form_load event, knowing that the form won't show up until the Form_load event was exited. In my vb.net app, I resize a bunch of controls, etc... in the Form_Load event, but it seems that when the form actually appears on the screen, there is still resizing going on. How can I make sure that the form shows up after all the resizing has been finished. Thanks.
  • 3. How to run VBA code from VB.Net
    I have made a macro that works fine in Word, but when I paste it into a VB.net project some of the code appears as 'not declared'. The code that shows not declared is activedocument, wdCollapseEnd and wdCollapseEnd. What reference/import am I missing. All help appreciated. ---- imports Word imports Microsoft.Office.Core --- Sub kims() Dim wordDocument As Word.Document Dim tableRange As Word.Range Dim pictureRange As Word.Range Dim pictureTable As Word.Table Dim feltet As Word.Field Set wordDocument = ActiveDocument wordDocument.Paragraphs.Add Set tableRange = wordDocument.Paragraphs.Last.Range Set pictureTable = wordDocument.Tables.Add(tableRange, 1, 1) Set pictureRange = pictureTable.Cell(1, 1).Range pictureTable.Columns.Item(1).Width = 120 pictureTable.Rows.Item(1).Height = 120 Dim picture As String picture = "c:\\test.jpg" Set pictureRange = ActiveDocument.Content pictureRange.Collapse Direction:=wdCollapseEnd pictureRange.Fields.Add pictureRange, Type:=wdFieldEmpty, Text:="INCLUDEPICTURE """ & picture & """" _ , PreserveFormatting:=False End Sub

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

Postby Paul M » Sun, 08 Jan 2006 19:49:59 GMT

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_strMDBFullPath, True)".

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

Thanks in advance

Paul M.




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

Postby TC » Sun, 08 Jan 2006 20:00:41 GMT

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]


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

Postby Armin Zingler » Sun, 08 Jan 2006 20:15:18 GMT

"Paul M" < XXXX@XXXXX.COM > schrieb


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


Armin 


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

Postby m.posseth » Sun, 08 Jan 2006 23:05:28 GMT


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]










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

Postby Cyril Gupta » Mon, 09 Jan 2006 00:03:26 GMT

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 



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

Postby Paul M » Sat, 14 Jan 2006 22:58:27 GMT


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

Similar Threads:

1.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_strMDBFullPath, True)".

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

Thanks in advance

Paul M.



2.Example code to create an MS Access db locally using VB.Net 2003

Hi, 

I am a beginner looking for example code on how to create an access
database for a local application. I need to create the database when
the app is first installed. I can do it with SQL 2000 but I am not
sure how to do create a db, tables and fields as a local mdb. Any help
or pointers to where I can find example code on this much appreciated.

Thanks
John

3.Open PW-Protected MS Access db using Excel VBA

I have code set up to open an Access database from within Excel using a VB 
module.  It works, but now I want to add a password to the Access database 
and I can not figure out how to do it.  Below is the open routine.  What do I 
need to add to it so it opens it with a password.

Sub OpenMsAccess()
    Dim AccessApp As Object
    
    Set AccessApp = CreateObject("Access.Application")
    AccessApp.Visible = True
    AccessApp.OpenCurrentDatabase "C:\TestDir\TestDb.mdb"
    'process data
    AccessApp.Quit
    Set AccessApp = Nothing
    
End Sub

4.Opening a query in MS Access with parameters using VB.net

I am trying to help a friend who is learning VB.net in school. I have
done VB programming for a number of years using VB 6. He needs to open
a query in an Access database that has parameters so he can work with
the returned records.

In VB 6, I use DAO and do it this way:

Dim db As Database
Dim rs As Recordset
Dim qd As QueryDef
Dim strPath as string


Set db = DBEngine.Workspaces(0).OpenDatabase(PATH TO DATABASE)
Set qd = dbDatabase.QueryDefs![QUERY NAME]
qd![PARAMETER NAME] = PARAMETER TO FEED QUERY
Set rs = qd.OpenRecordset()

	... CODE TO USE THE RECORDSET

rs.close
db.close

For VB.net, it appears that you have to use OLE DB and it really seems
to be way more complicated than it should be. Does anyone have a code
snippet where the code simply sets the recordsource to the query and
passes the query the parameters so he can work with the recordset?

Thanks,
Craig

5.Copying MS Access object (Forms etc) using VB from 1 db to another

Hello,
        I have a VB .net program that I would like to be able to to do the
following:

Open a source Access database
Get all the forms, reports, tables etc
Copy them all to a second target MS Access database

I tried using (in vb .net):

TargetDB.DoCmd.CopyObject

but I cant seem to get all the parameters right.

Can anyone help?

Cheers
Paul


6. Copy access objects (reports, queries, etc) from one Access db to another using VB.net

7. Copying MS Access object (Forms etc) using VB from 1 db to another

8. ASP.NET VB.NET Login page using Access db



Return to VB.NET

 

Who is online

Users browsing this forum: No registered users and 10 guest