open a Microsoft Access form

G

Guest

Hi,

How do I open a Microsoft Access 2003 form from Visual Basic.net

Thanks in advance
bbdobuddy
 
P

Paul Clement

¤ Hi,
¤
¤ How do I open a Microsoft Access 2003 form from Visual Basic.net
¤

I used the Office PIA
(http://msdn.microsoft.com/library/d...y/en-us/stagsdk/html/stconPIAs_HV01083002.asp)
for this but you can also use the interop assembly generated when you add the Access COM reference
to your project:


Public Sub AutomateAccess()

Dim AccessApplication As New Microsoft.Office.Interop.Access.Application

If Not AccessApplication.Visible = True Then
AccessApplication.Visible = True
End If

AccessApplication.OpenCurrentDatabase("e:\My Documents\db1.mdb")
AccessApplication.DoCmd.OpenForm("MyAccessFormName",
Microsoft.Office.Interop.Access.AcFormView.acNormal)

'...
'...

AccessApplication.Quit()

End Sub


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
M

moondaddy

I'm trying to use similar code as you used below, however, as mentioned in
the link you provided, the PIAs are not to be used in the application setup
process. If I don't include them in the setup then this code wont run on
the client. If I do include them in the setup, the code will run on the
client, but 1) the msdn documentation says we don't have the right to
distribute these, and 2) by installing these on the client we could corrupt
the office registration on the client when they do an un-install of our
applications. I was confused by the documentation in the URL as it didn't
clarify how to distribute the .net app and have the client be able to use
the code you listed below.

Do you have any advise on how to go about this?

Here's me code which is similar to your code:


Public Function OpenApp() As FileMngr
Try
Dim sFile As String = "some path to ms access"

Dim sCrit As New StringBuilder
Dim dr As wsMain.dsUser.tbCtlRow
sCrit = "some stuff for access to use"
'Startup Access Now
Dim AccessApplication As New Access.Application
'Make it visible ?should we do this later?
If Not AccessApplication.Visible = True Then
AccessApplication.Visible = True
End If
'Open app
AccessApplication.OpenCurrentDatabase(sFile)
'Call a function to start things running and pass in the user rights
that will be used to initalize everything
AccessApplication.Run("Main", sCrit.ToString)
Return FileMngr.Success

Catch ex As Exception
ErrLog(ex)
End Try
End Function


The msdn documentaion said to set the property (Copy Local) on the reference
to access to "False". When I did that, I get the following error:



System.IO.FileNotFoundException: File or assembly name Interop.Access, or
one of its dependencies, was not found.
File name: "Interop.Access"
at TransAct.ClientAppHelper.OpenApp()
at TransAct.frmMain.OpenClientApp() in
D:\nwis\Apps\LandMan\VS\TransAct\TransAct\frmMain.vb:line 553

=== Pre-bind state information ===
LOG: DisplayName = Interop.Access, Version=9.0.0.0, Culture=neutral,
PublicKeyToken=null
(Fully-specified)
LOG: Appbase = D:\nwis\Apps\LandMan\VS\TransAct\TransAct\bin\
LOG: Initial PrivatePath = NULL
Calling assembly : TransAct, Version=1.0.1887.28847, Culture=neutral,
PublicKeyToken=null.
===

LOG: Policy not being applied to reference at this time (private, custom,
partial, or location-based assembly bind).
LOG: Post-policy reference: Interop.Access, Version=9.0.0.0,
Culture=neutral, PublicKeyToken=null
LOG: Attempting download of new URL
file:///D:/nwis/Apps/LandMan/VS/TransAct/TransAct/bin/Interop.Access.DLL.
LOG: Attempting download of new URL
file:///D:/nwis/Apps/LandMan/VS/TransAct/TransAct/bin/Interop.Access/Interop.Access.DLL.
LOG: Attempting download of new URL
file:///D:/nwis/Apps/LandMan/VS/TransAct/TransAct/bin/Interop.Access.EXE.
LOG: Attempting download of new URL
file:///D:/nwis/Apps/LandMan/VS/TransAct/TransAct/bin/Interop.Access/Interop.Access.EXE.
</Exception>
</Errors>
<Errors d2p1:id="2" d2p1:TimeStamp="2005-03-02T16:10:40.6916071-06:00"
xmlns:d2p1="http://tempuri.org/dsErrorHandler.xsd">
<Exception>System.IO.FileNotFoundException: File or assembly name
Interop.Access, or one of its dependencies, was not found.
File name: "Interop.Access"
at TransAct.ClientAppHelper.OpenApp()
at TransAct.frmMain.OpenClientApp() in
D:\nwis\Apps\LandMan\VS\TransAct\TransAct\frmMain.vb:line 553

=== Pre-bind state information ===
LOG: DisplayName = Interop.Access, Version=9.0.0.0, Culture=neutral,
PublicKeyToken=null
(Fully-specified)
LOG: Appbase = D:\nwis\Apps\LandMan\VS\TransAct\TransAct\bin\
LOG: Initial PrivatePath = NULL
Calling assembly : TransAct, Version=1.0.1887.28847, Culture=neutral,
PublicKeyToken=null.
===

LOG: Policy not being applied to reference at this time (private, custom,
partial, or location-based assembly bind).
LOG: Post-policy reference: Interop.Access, Version=9.0.0.0,
Culture=neutral, PublicKeyToken=null
LOG: Attempting download of new URL
file:///D:/nwis/Apps/LandMan/VS/TransAct/TransAct/bin/Interop.Access.DLL.
LOG: Attempting download of new URL
file:///D:/nwis/Apps/LandMan/VS/TransAct/TransAct/bin/Interop.Access/Interop.Access.DLL.
LOG: Attempting download of new URL
file:///D:/nwis/Apps/LandMan/VS/TransAct/TransAct/bin/Interop.Access.EXE.
LOG: Attempting download of new URL
file:///D:/nwis/Apps/LandMan/VS/TransAct/TransAct/bin/Interop.Access/Interop.Access.EXE.



Thanks for any help anyone can offer.
 
P

Paul Clement

¤ I'm trying to use similar code as you used below, however, as mentioned in
¤ the link you provided, the PIAs are not to be used in the application setup
¤ process. If I don't include them in the setup then this code wont run on
¤ the client. If I do include them in the setup, the code will run on the
¤ client, but 1) the msdn documentation says we don't have the right to
¤ distribute these, and 2) by installing these on the client we could corrupt
¤ the office registration on the client when they do an un-install of our
¤ applications. I was confused by the documentation in the URL as it didn't
¤ clarify how to distribute the .net app and have the client be able to use
¤ the code you listed below.
¤
¤ Do you have any advise on how to go about this?
¤
¤ Here's me code which is similar to your code:
¤
¤
¤ Public Function OpenApp() As FileMngr
¤ Try
¤ Dim sFile As String = "some path to ms access"
¤
¤ Dim sCrit As New StringBuilder
¤ Dim dr As wsMain.dsUser.tbCtlRow
¤ sCrit = "some stuff for access to use"
¤ 'Startup Access Now
¤ Dim AccessApplication As New Access.Application
¤ 'Make it visible ?should we do this later?
¤ If Not AccessApplication.Visible = True Then
¤ AccessApplication.Visible = True
¤ End If
¤ 'Open app
¤ AccessApplication.OpenCurrentDatabase(sFile)
¤ 'Call a function to start things running and pass in the user rights
¤ that will be used to initalize everything
¤ AccessApplication.Run("Main", sCrit.ToString)
¤ Return FileMngr.Success
¤
¤ Catch ex As Exception
¤ ErrLog(ex)
¤ End Try
¤ End Function
¤
¤
¤ The msdn documentaion said to set the property (Copy Local) on the reference
¤ to access to "False". When I did that, I get the following error:
¤
¤
¤
¤ System.IO.FileNotFoundException: File or assembly name Interop.Access, or
¤ one of its dependencies, was not found.
¤ File name: "Interop.Access"
¤ at TransAct.ClientAppHelper.OpenApp()
¤ at TransAct.frmMain.OpenClientApp() in
¤ D:\nwis\Apps\LandMan\VS\TransAct\TransAct\frmMain.vb:line 553
¤
¤ === Pre-bind state information ===
¤ LOG: DisplayName = Interop.Access, Version=9.0.0.0, Culture=neutral,
¤ PublicKeyToken=null
¤ (Fully-specified)
¤ LOG: Appbase = D:\nwis\Apps\LandMan\VS\TransAct\TransAct\bin\
¤ LOG: Initial PrivatePath = NULL
¤ Calling assembly : TransAct, Version=1.0.1887.28847, Culture=neutral,
¤ PublicKeyToken=null.
¤ ===
¤
¤ LOG: Policy not being applied to reference at this time (private, custom,
¤ partial, or location-based assembly bind).
¤ LOG: Post-policy reference: Interop.Access, Version=9.0.0.0,
¤ Culture=neutral, PublicKeyToken=null
¤ LOG: Attempting download of new URL
¤ file:///D:/nwis/Apps/LandMan/VS/TransAct/TransAct/bin/Interop.Access.DLL.
¤ LOG: Attempting download of new URL
¤ file:///D:/nwis/Apps/LandMan/VS/TransAct/TransAct/bin/Interop.Access/Interop.Access.DLL.
¤ LOG: Attempting download of new URL
¤ file:///D:/nwis/Apps/LandMan/VS/TransAct/TransAct/bin/Interop.Access.EXE.
¤ LOG: Attempting download of new URL
¤ file:///D:/nwis/Apps/LandMan/VS/TransAct/TransAct/bin/Interop.Access/Interop.Access.EXE.
¤ </Exception>
¤ </Errors>
¤ <Errors d2p1:id="2" d2p1:TimeStamp="2005-03-02T16:10:40.6916071-06:00"
¤ xmlns:d2p1="http://tempuri.org/dsErrorHandler.xsd">
¤ <Exception>System.IO.FileNotFoundException: File or assembly name
¤ Interop.Access, or one of its dependencies, was not found.
¤ File name: "Interop.Access"
¤ at TransAct.ClientAppHelper.OpenApp()
¤ at TransAct.frmMain.OpenClientApp() in
¤ D:\nwis\Apps\LandMan\VS\TransAct\TransAct\frmMain.vb:line 553
¤
¤ === Pre-bind state information ===
¤ LOG: DisplayName = Interop.Access, Version=9.0.0.0, Culture=neutral,
¤ PublicKeyToken=null
¤ (Fully-specified)
¤ LOG: Appbase = D:\nwis\Apps\LandMan\VS\TransAct\TransAct\bin\
¤ LOG: Initial PrivatePath = NULL
¤ Calling assembly : TransAct, Version=1.0.1887.28847, Culture=neutral,
¤ PublicKeyToken=null.
¤ ===
¤
¤ LOG: Policy not being applied to reference at this time (private, custom,
¤ partial, or location-based assembly bind).
¤ LOG: Post-policy reference: Interop.Access, Version=9.0.0.0,
¤ Culture=neutral, PublicKeyToken=null
¤ LOG: Attempting download of new URL
¤ file:///D:/nwis/Apps/LandMan/VS/TransAct/TransAct/bin/Interop.Access.DLL.
¤ LOG: Attempting download of new URL
¤ file:///D:/nwis/Apps/LandMan/VS/TransAct/TransAct/bin/Interop.Access/Interop.Access.DLL.
¤ LOG: Attempting download of new URL
¤ file:///D:/nwis/Apps/LandMan/VS/TransAct/TransAct/bin/Interop.Access.EXE.
¤ LOG: Attempting download of new URL
¤ file:///D:/nwis/Apps/LandMan/VS/TransAct/TransAct/bin/Interop.Access/Interop.Access.EXE.
¤
¤
¤
¤ Thanks for any help anyone can offer.

The references above are not to the Office PIAs but to the generic interop assemblies that are
created at design-time by the Visual Studio .NET IDE when you add one of the Office applications to
your project.

You should be able to deploy those interop assemblies with your app.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top