Results 1 to 13 of 13

Thread: [RESOLVED] Run query within a query using code [RESOLVED]

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member greaseman's Avatar
    Join Date
    Jul 2005
    Location
    Somewhere, out there...
    Posts
    295

    Resolved [RESOLVED] Run query within a query using code [RESOLVED]

    I'm having a bit of a headache with trying to run a delete query using the results of a select query, in VB code. My first query runs OK, but when I try running the second query, I keep getting a message, "Object required."

    I've enclosed my code that is causing the problem..... if y'all could take a look at it and tell me the erors of my ways, I would be very happy.
    VB Code:
    1. Dim rsMstrPN As New ADODB.Recordset
    2.     Dim rsDuplicates As New ADODB.Recordset
    3.     Dim strSQL As String
    4.     Dim strErrMsg As String
    5.     Dim lngRecCount As Long
    6.     Dim lngTotalRec As Long
    7.     Dim strPartId As String
    8.  
    9. '==========================================================================
    10. ' Variable Initialization Section
    11. '==========================================================================
    12.     DeletePNdata = False
    13. '==========================================================================
    14. ' Code Section
    15. '==========================================================================
    16.  
    17.     strSQL = ""
    18.     strSQL = strSQL & "select DuplicatePartsBad.PNID from DuplicatePartsBad "
    19.     strSQL = strSQL & "Order by DuplicatePartsBad.PNID"
    20.     rsDuplicates.Open strSQL, conJetMasterDb, adOpenStatic,    adLockReadOnly, adCmdText
    21.     If Not (rsDuplicates.EOF = True And rsDuplicates.BOF = True) Then
    22.         rsDuplicates.MoveFirst
    23.         Do While Not rsDuplicates.EOF
    24.              strPartId = rsDuplicates!PNID
    25.              strSQL = ""
    26.              strSQL = strSQL & "Delete * from MasterPN where MasterPN.PNId    = " & strPartId & "; "
    27.              Debug.Print strSQL
    28.              rsMasterPN.Open strSQL, conJetMasterDb, adOpenStatic, adLockOptimistic, adCmdText
    29.         Loop
    30.     End If
    31.    
    32.     rsMstrPN.Close
    33.     rsDestination.Close

    Thaks to all of you who help out this myopic programmer!!
    Last edited by Hack; Mar 15th, 2006 at 07:04 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width