• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 557
  • Last Modified:

Access query in vb.net 2010

1. I am new to vb.net. My question is: can you run querys from an access database 2010 from vb.net , if so can someone explain to my how?

2. Can you do the same with macros? if so how.

3. I will need to do the following with-in vb.net:
Add a record
update record
delete record

I will need some examples. Please help.
  • 2
1 Solution
There are 2 primary ways that you can interact with an Access db from .NET.  1) Use ADO.NET to run SQL statements against the db as a backend. 2)  Use Access automation to run Access as an application an have the Access application do the queries, etc.

Option 1 is generally preferred  when possible.  However for doing very Access specific things like running Access macros, interacting directly with Access forms and reports you need option 2.

For adding, updating, and deleting records option 1 is would usually be the way to go.

There are many specific examples of interacting with databases of all sorts using VB.NET and ADO.NET.  If you could give a little more info on what you are trying to do it would be helpful.  For instance, web or windows app?  Do you need to see/manipulate the data you are updating/changing?
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
The only way to run a Macro would be through automation. I'd strongly advise against doing that, and instead move your Macro logic to .NET code (otherwise what's the point of doing this in .NET?).
PoppygbAuthor Commented:
I wish I could get some code examples or a good book that goes more into detal.
Other wise GOOD WORK
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Here's a link on automating Access from .NET:


You need a Reference to the Access library, and then you do this:

Dim oAccess As Access.Application
oAccess = New Access.ApplicationClass
oAccess.OpenCurrentDatabase("Path to your db")

'/ now use the oAccess object:
oAccess.Docmd.RunMacro "YourMacroName"

'/ be sure to close the object:
oAccess = Nothing

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now