Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running and update query 1

Status
Not open for further replies.

BPMan

Programmer
Jun 25, 2002
163
US
I have an update query in my access database called savings.
I have an VB program that uses this database and i want to run this savings update query every time i load the program...
i know that i need to put stuff in the load of my first form but how do i run a query in my database?
Thanks
 
I'm no expert on this, but this seems to do the trick:

Code:
    Dim CN As New ADODB.Connection
    Dim CM As New ADODB.Command
    
    With CN
        .Provider = "Microsoft.Jet.OLEDB.4.0"
        .Mode = adModeReadWrite
        .CursorLocation = adUseClient
        .Open "path\myDataBase.mdb"
    End With

    With CM
        .CommandText = "myUpdateQuery"
        .ActiveConnection = CN
        .Execute
    End With
    
    Set CN = Nothing
    Set CM = Nothing
 
Well, depending on the provider, and if no parameters are passed, this may work even easier:


conn.Execute "EXECUTE myQuery", Options:= cmdStoredProc


Then, you can use the additional parameter to make it run faster (ExecuteNoRecords, meaning rather no need to return records to the connection as in a recordset), and, using a variable if so desired to determine if any records got processed:

conn.Execute "EXECUTE myQuery", RecordsAffected:=lRecordsAffected, Options:= cmdStoredProc + adExecuteNoRecordsFalse
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top