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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating an ADODB connection

Status
Not open for further replies.

deharris2003

Programmer
Jul 1, 2003
41
US
I am trying to run a query in Access that will update an SQL table, Which I know I can do. Problem is the query always asking for the DSN. It is my inderstanding that if I run the Query in VBA then I can code the ADODB connection string. I know how to do this in ASP but VBA is different. Here is what have already and it does not work. Any help is much appreciated.

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "PROVIDER=SQLOLEDB;DATA SOURCE=data1;UID=DBS_TEMP;PWD=DBS_TEMP"

strSQL = "DELETE FROM dbo_Online_Media " & _
"WHERE dbo_Online_Media.IDX_HP_ID = '184'"

Conn.Execute (strSQL)
 
Dim cn As New Connection
Dim ref as integer, connString As String
connString = "provider=SQLOLEDB.1;" & _
"User ID=sa;Initial Catalog=pubs;" & _
"Data Source=bigtuna;" & _
"Persist Security Info=False"
cn.ConnectionString = connString
cn.Open connString

cn.execute strSQL, ref

if ref > 0 then
Debug.Print "Number of records deleted = "; ref
end if
cn.Close
Set cn = Nothing

Make sure you have a reference set to the ADO library.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top