Looping through arrays

Results 1 to 2 of 2

Thread: Looping through arrays

  1. #1
    Join Date
    Dec 1969

    Default Looping through arrays

    The code below is supposed to pull values from two tables and then add them to a third.<BR><BR>In practice it adds values to the wrong columns for a couple of rows and then throws an "Out of range" error.<BR><BR>It is supposed to add a CatID, then a JobID, then move to a new row. It actually adds a CatID to the CatID AND JobID field, then a JobID to then next CatID AND JobID field.<BR><BR>Any help?<BR><BR>strSQL = "SELECT Categories.CategoryID, JobID FROM Jobs INNER JOIN Categories ON "&_<BR>"Jobs.Category = Categories.CategoryName AND Categories.SiteID = 2 WHERE Jobs.SiteID = 2 ORDER BY JobID ASC" <BR> <BR>objRec.Open strSQL, objConn, , adLockOptimistic, adCmdText<BR><BR><BR>Dim aTable1Values<BR>aTable1Values = objRec.GetRows()<BR><BR><BR>objRec.Close<BR><BR>ob jRec.Open "JobsAndCats", ObjConn, adOpenKeySet, adLockOptimistic, adCmdTable<BR><BR><BR>Dim iRowLoop, iColLoop<BR>For iRowLoop = 0 to UBound(aTable1Values, 2)<BR><BR>objRec.AddNew<BR><BR> For iColLoop = 0 to UBound(aTable1Values, 1)<BR><BR>objRec(iColLoop) = aTable1Values(iRowLoop, iColLoop) <BR><BR><BR> Next &#039;iColLoop<BR><BR> objRec.Update<BR><BR><BR>Next &#039;iRowLoop<BR><BR>objRec.Close<BR>Set objRec = Nothing<BR><BR><BR>objConn.Close<BR>Set objConn = Nothing<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default Why cant you do the eitire thing in the SQL

    insert into Table1 (....)<BR>select ...... from Table2<BR>join table3 on (..)<BR><BR><BR>

Posting Permissions

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