I am using code I found here to create a passthrough query to SQL
pass-through query with input parmeter
I'm getting duplicate records.
First time in I get my Insert record at the line in code below
DoCmd.OpenQuery strQueryName
I then return to data entry form and input a new record.
I step through the code and when it gets to the line
Set cat.Procedures(strQName).Command = cmd
I get an exact duplicate of the record I just inserted into my table. When the code returns to the DoCmd.Openquery noted above, I get my new inserted record.
I thought it was running the query again (strQName) but if I stop execution before the set cat.procedures... line of code, my InsertQuery contains the correct new query parameters.
How can I clear my query yet keep the correct ODBC variables?
I am using
Microsoft ActiveX Data Objects 6.1 Library and
Microsoft ADO Ext. 2.8 for DDL and Security
for the ADOX and ADODB references.
[code]
Public Sub ExecutePassThroughtest(txtID, txtLastName, txtFirstName, txtMI, strOperator, txtroom, txtbldg, txtcit, txtType, txtIssueDate, dtchgDate, txtExpirationDate)
On Error GoTo err_executepassthroughttest
Dim strTSQL As String
Dim strQueryName As String
'this is a pass through query I created in this db
strQueryName = "Insertbadge"
' this is the stored procedure in sql
strTSQL = "EXEC pr_InsertVIP '" & txtID & "', '" & txtLastName & "', '" & txtFirstName & "', '" & txtMI & "', '" & strOperator & "', '" & txtroom & "', '" & txtbldg & "', '" txtcit & "', '" & txtType & "', '" & txtIssueDate & "', '" & dtchgDate & "', '" & txtExpirationDate & "'"
Call BuildPassThrough(strQueryName, strTSQL)
DoCmd.OpenQuery strQueryName
End Sub
Public Sub BuildPassThrough( _
ByVal strQName As String, _
ByVal strSQL As String)
Dim cat As ADOX.Catalog
Dim cmd As ADODB.Command
Set cat = New ADOX.Catalog
Set cat.ActiveConnection = CurrentProject.Connection
Set cmd = cat.Procedures(strQName).Command
' Verify query is a pass-through query
cmd.Properties("Jet OLEDB:ODBC Pass-Through Statement") = True
cmd.CommandText = strSQL
Set cat.Procedures(strQName).Command = cmd
Set cmd = Nothing
Set cat = Nothing
End Sub
[\code]