Solved

VB.net Open Access Functionality

Posted on 2013-12-04
5
570 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:murbro
  • 2
  • 2
5 Comments
 
LVL 21
ID: 39696534
try:

appAccess.DoCmd.RunCommand  257 ' acCmdImport 

Open in new window

0
 

Author Comment

by:murbro
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 250 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 250 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:murbro
ID: 39698459
Thanks very much
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

730 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