Execute SQL Query using Visual Basic Application

After we learned how to connecting to server using vba. Now, we learn how to execute sql query using vba.

Here some examples:

Con.execute  ”Select * from yourtable

Con.execute “update yourtable set yourfield = value

Con.execute “delete from yourtable

Easy huh…

Connecting to Server with Visual Basic Application

In Excel, we can connect to server and use the resource of database. Connecting to server in Excel use the same way we connect to server with visual basic.

Here some codes we can use to connect to server with visual basic application.

Dim con As New ADODB.Connection

If con.State = 1 Then con.Close

Set con = Nothing

con.Open “Driver={SQL SERVER};Server=yourservername ;database=yourdatabasename;”

so, enjoy it.

Dansette