?
Solved

How do i exeucte a query thats in an access database through VB6?

Posted on 2008-02-06
3
Medium Priority
?
135 Views
Last Modified: 2010-08-05
I have an access database with several querys in and a VB6 program the manipulates access. I want to be be able to add an 'update' button that copys the contects from one access table then pastes it in an empty access table. This table maybe updated so it needs to overwrite what may already be in it.
I have included the main code so far but its the middle bit i havn't got!
Private Sub btnUpdate_Click()
    Dim rA As Integer
    Dim db As New ADODB.Connection
    Dim sSQL As String
    
   
   db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = \\Server\test Database\testDatabase.mdb"
   db.Open
  
      MsgBox "Completed!!"
   
      db.Close
      Set db = Nothing
End Sub

Open in new window

0
Comment
Question by:wilko100
3 Comments
 
LVL 4

Accepted Solution

by:
jpeca earned 1000 total points
ID: 20832119
You can treat Access querry as store procedure

db.Execute "EXEC" & queryname
0
 
LVL 20

Assisted Solution

by:clarkscott
clarkscott earned 1000 total points
ID: 20833205
Private Sub btnUpdate_Click()
    Dim rA As Integer
    Dim db As New ADODB.Connection
    dim rst as adodb.recordset
    Dim sSQL As String


   
   db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = \\Server\test Database\testDatabase.mdb"
   db.open
      '--- 1st example -----
       sSQL = "Select * from YourTable"
       set rst = db.openrecordset(sSQL)
      if not rst.eof and not rst.bof then
               rst.movefirst
               do while not rst.eof
                         '---- do stuff
                       rst.movenext
               loop
       end if
       rst.close
       set rst = nothing    
 '---- 2nd example ---
    sSQL = "INSERT x into y ......."
    db.execute sSQL
   
      MsgBox "Completed!!"
   
      db.Close
      Set db = Nothing



Scott C
0
 

Author Closing Comment

by:wilko100
ID: 31428470
Sorry been away, thanks you guys sorted it
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

599 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