?
Solved

VB.net Open Access Functionality

Posted on 2013-12-04
5
Medium Priority
?
610 Views
Last Modified: 2013-12-05
Hi. I am using the following VB.net code in my Excel add-in to open an Access database
      I want to include additional code to open up the form that allows the user to create
      a new import specification. How would I do that?

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

        appAccess.OpenCurrentDatabase("C:\Users\murbro\Documents\Database1.accdb")

        appAccess.Visible = True
0
Comment
Question by:Murray Brown
  • 2
  • 2
5 Comments
 
LVL 21
ID: 39696534
try:

appAccess.DoCmd.RunCommand  257 ' acCmdImport 

Open in new window

0
 

Author Comment

by:Murray Brown
ID: 39696587
I have Access 2007 and 2013 on my machine and got an error
You tried to perform an operation involving a function or feature that was not installed in this version of Microsoft Access.

Is there any way of writing code to check the version first
0
 
LVL 21

Accepted Solution

by:
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP earned 1000 total points
ID: 39696826
I just checked and

DoCmd.RunCommand  257 ' acCmdImport 

Open in new window


is only for Access 2003 and older.  

Sorry about that. I was working in Access 2003 at the time I answered this.

The import wizards changed in Access with 2007 and later. There are now separate Ribbon options for the different data sources.

The constant change from the single acCmdImport

to these options:

acCmdImportAttachAccess  544  Opens an Access import dialog box
acCmdImportAttachdBase   552  Opens a dBase import dialog box
acCmdImportAttachExcel     545  Opens an Excel import dialog box
acCmdImportAttachHTML    550  Opens an HTML import dialog box
acCmdImportAttachLotus    554  Opens a Lotus import dialog box
acCmdImportAttachODBC   549  Opens an ODBC import dialog box
acCmdImportAttachOutlook 551 Opens an Outlook import dialog box
acCmdImportAttachParadox 553 Opens a Paradox import dialog box
acCmdImportAttachSharePointList 547 Opens a Sharepoint import dialog box
acCmdImportAttachText      546  Opens a Text import dialog box
acCmdImportAttachXML      548  Opens an XML import dialog box

Open in new window


You have to specify which one you want.

Example:

Opens an Excel import dialog box
DoCmd.RunCommand  545 ' acCmdImportAttachExcel

Open in new window

0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 1000 total points
ID: 39696904
Relying on the menu/ribbons commands as RunCommand does is never a good idea. What will they invent when they decide to replace the ribbons by something else as a marketing tool to sell a new version that does less than the previous one :-).

Believe me. Having worked with each version of Access since 1.0, I can tell you that it is sure to bomb one day or another after an "upgrade". It is better to call Access Internal command:

appAccess.DoCmd.OpenForm("yourForm")

You might still have a problem with that however, since .NET is very sensitive to the version of any Office program that you reference. If you reference a specific version, it will definitively work on that version of Access, but not necessarily on another. If this is the case, you need to use Late Binding (working with Object variables) instead of work with Early Binding (defining specifically typed variables).
0
 

Author Closing Comment

by:Murray Brown
ID: 39698459
Thanks very much
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question