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

Pass-through Delete Query

Status
Not open for further replies.

jambai

Programmer
Mar 21, 2007
58
US
I am trying to delete records in the SQL Server from MS Access forms. I got error 3065 cannot execute a select qury, when trying the below code.

Dim qdfPassThrough As DAO.QueryDef
Dim rstPassThrough As DAO.Recordset
Dim strConnect As String
Dim dbCurrent As DAO.Database
Set qdfPassThrough = CurrentDb.CreateQueryDef("")
strConnect = "Driver=SQL SERVER;SERVER = NTSQLSERVER;Database=TEST;UID=mlp;password='';"
qdfPassThrough.Connect = "ODBC;" & strConnect
qdfPassThrough.SQL = "DELETE FROM tempDefTable"
qdfPassThrough.Execute

Please help me

Thanks
Jambai
 
Maybe this?

Code:
DELETE tempDefTable FROM tempDefTable

HOpe it helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
You have a stray quote here:

password='';"

I think you mean to just leave it blank?

You might need to use ADO rather then DAO, but I am not sure about this.

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
Open a ADO connection to your SQL server, and execute your SQL delete statement!

Code:
Dim SQLCnn as ADODB.Connection

Set SQLCnn= New ADODB.Connection
With SQLCnn
   .ConnectionString ="..."
   .Open
   .Execute "DELETE FROM tempDefTable",,129
   .Close
End With
Set SQLCnn = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top