[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

run access query in vb

Posted on 2004-11-01
6
Medium Priority
?
185 Views
Last Modified: 2008-03-06
I have an Access Database (Suite.mdb) with a VB 6.0 front end.  I would like to run a query in the database (tblContactsQuery) from the VB front end.  Any ideas?  Also, the database is attached with an ADODC to the VB front end.

thanks!
0
Comment
Question by:drewderocco
[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
  • 3
  • 2
6 Comments
 
LVL 34

Expert Comment

by:flavo
ID: 12469542
Hi drewderocco,

example (not the best with ado, so im not sure about the connection string

Dim db As ADODB.Connection
Set db = New ADODB.Connection

'set connection

db.Execute sMyUpdateQuery

Idea???

Dave
0
 
LVL 12

Accepted Solution

by:
Bob Lamberson earned 1000 total points
ID: 12470267
Here is the syntax

Private Sub Form_Load()
Dim ProductsQuery As String
Dim cn As ADODB.Connection
Dim cmd As String
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=<c:\aaa testing>\Suite.mdb;User Id=admin;Password="

cmd = "tblContactsQuery"

cn.Execute cmd

End Sub


Bob
0
 
LVL 12

Expert Comment

by:Bob Lamberson
ID: 12470272
add your path to the mdb where I have    <c:\aaa testing>

Bob
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

Author Comment

by:drewderocco
ID: 12481580
sorry, I should have been more specific.  When I ask this query to run, the command in VB is in the menu of the form.  I have listed "Query Contacts" as the verbage in the menu.  When I choose this, I would like the query to run in access.

thanks!
0
 
LVL 12

Expert Comment

by:Bob Lamberson
ID: 12483667
go to the code behind the form and in the left hand drop down box, select the menu option name "Query Contacts". Then in the right hand dropdown list select the Query Contacts_Click event and enter the code so it will end up looking like this>

Private Sub Private Sub QueryContacts_Click()    ' **NOTE HERE that your event name may be different from the display name.
Dim ProductsQuery As String
Dim cn As ADODB.Connection
Dim cmd As String
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=<c:\aaa testing>\Suite.mdb;User Id=admin;Password="

cmd = "tblContactsQuery"

cn.Execute cmd
End Sub

**You can find the event name of the menu option by going to the form, right clicking, left click Menu Editor, select the menu option with the caption "Query Contacts" and see what the Name is.

-Bob
0
 

Author Comment

by:drewderocco
ID: 12490653
Bob:
Works like a charm.  Thanks!
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

649 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