Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 27th, 2014, 12:35 PM
Registered User
 
Join Date: Feb 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default passthrough query duplicate records

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]





Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Passthrough Query Rood67 Access VBA 13 May 1st, 2012 04:20 PM
duplicate records vanitha SQL Server 2000 4 June 2nd, 2007 04:35 PM
duplicate records vanitha Reporting Services 2 May 31st, 2007 01:54 AM
Duplicate Records mrookey Dreamweaver (all versions) 1 April 15th, 2005 11:23 AM
passthrough query Snowingnow Access 3 November 23rd, 2004 11:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.