Solved

VB.net Open Access Functionality

Posted on 2013-12-04
5
545 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Gantt chart 2 19
Multiple queries for a form 14 22
After moving to webstite page stopped working 7 52
Data Conversion 11 12
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now