I should know how to do this, but have struggled for hours without success. I have stored procedure on SQL Server 2005 that updates six fields, It runs fine in SQL Server query window. However, I need to call the stored procedure from VBA.
The following code snippet is where I am getting an error:
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDefs
‘Dim rst As DAO.Recordset
Dim strSQL As String
Dim strUID As String
Dim strPWD As String
Dim strConnect As String
Dim strDATABASE As String
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs
‘Set qdf = dbs.QueryDef
strSQL = “EXEC SDUpdate @SID = ” & Me.SID & _
“, @SName = ” & Me.txtName & _
“, @SAddress1 = ” & Me.txtAddress1 & _
“, @SClosedDate = ” & Me.txtClosed & _
“, @SClosed = ” & Me.chkClosed & _
“, @SInactive = ” & Me.chkInactive & _
“, @S_Pkey = ” & Me.txtPkey & “;”
strUID = “KWVH”
strPWD = “kwvh”
strDATABASE = “KWVH_SQL”
strConnect = “ODBC;DRIVER={SQL Server}” _
& “;SERVER = LAPTOP ” _
& “;DATABASE = ” & strDATABASE _
& “;UID =” & strUID _
& “;PWD =” & strPWD & “;”
qdf.Connect = strConnect
qdf.SQL = strSQL
qdf.ReturnsRecords = False
qdf.Execute
Set qdf = Nothing
Set dbs = Nothing
End Sub
I get the following error on the “qdf.Connect = strConnect” line
Method or data member not found
The “.Connect” is highlighted each time.
I am also not 100% certain I have the Dim qdf correct. Should it be ‘QueryDef’ or ‘Querydefs’? Any ideas are greatly appreciated.
Ken
Even if you are on the right track, you’ll get run over if you just sit there.
Will Rogers