Solved

VB.net Open Access Functionality

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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