Results 1 to 4 of 4

Thread: More on the Weird VB code/Access 2000

  1. #1

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819

    More on the Weird VB code/Access 2000

    OK, it works for my brother. But he said that the table he is updating from has almost 20,000 records and the code has been running for 15 minutes and is still going.

    My question now (for all you SQL geniuses) is can all these queries and recordsets be combined into a single update query using sub-queries?

    VB Code:
    1. sSQL_NEW = "SELECT * FROM New_Table"
    2. Set RST_NEW = CurrentDb.OpenRecordset(sSQL_NEW, dbOpenDynaset) ' works fine for me
    3.  
    4. sSQL_LG = "SELECT * FROM Big_Table ORDER BY ID ASC"
    5. Set RST_LG = CurrentDb.OpenRecordset(sSQL_LG, dbOpenDynaset)
    6.  
    7. With RST_LG
    8.   .MoveFirst
    9.   Do Until .EOF
    10.     sSQL_SM = "SELECT TOP 1 * FROM Small_Table WHERE ID < " & !ID & " ORDER BY ID DESC"
    11.     Set RST_SM = CurrentDb.OpenRecordset(sSQL_SM, dbopensnapshot)
    12.     RST_NEW.AddNew
    13.        RST_NEW!ID = !ID
    14.        RST_NEW!Loan = !Loan
    15.        RST_NEW!Pmt = !Pmt
    16.        RST_NEW!Inv = RST_SM!Inv
    17.     RST_NEW.Update
    18.     .MoveNext
    19.   Loop
    20. End With

  2. #2
    DerFarm
    Guest
    If I'm reading this correctly, you want the maximum ID from small
    table that is not equal to the current big table ID and then you do
    stuff to it. Is this correct?

  3. #3
    Hyperactive Member MetallicaD's Avatar
    Join Date
    Feb 2001
    Location
    Tallahassee, FL
    Posts
    488
    If you want to do something similar to what DerFarm said.. you dont need to loop through everything just to find that value.. you can have SQL pull that value for you.. give us, in text format, what you are looking for and someone will create the SQL for you.. should be that simple

    -mcd
    [vbcode]
    '*****************************
    MsgBox "MCD :: [email protected]", vbInformation + vbOKOnly, "User"
    '*****************************
    [/vbcode]

  4. #4

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    Right. There are three tables. The third table is populated from a combination of items from the 1st and 2nd tables.

    The items from the 2nd table are selected where the ID of the second table is the Greatest ID that is less than the ID of the 1st table. That's why we did a TOP 1 and SORT DESC.

    I have no idea how to write this query as an update query. My brother is experimenting with sending the data to excel and seeing if it can do it faster.

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