Solved

VB.net Open Access Functionality

Posted on 2013-12-04
5
578 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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