Multiple recordset in single function in access

lokeshsu

Board Regular
Joined
Mar 11, 2010
Messages
178
Hi all,

can we open multiple recordset in a single function. i have a code where i have to create folder and subfolders according to the table. so i want to use multiple recordset and created folders using queries with in the do while loop. below is the code, but i am unable to open multiple record set in a single function
Code:
 sql1 = "SELECT Tbl_Location.Region_Num FROM Tbl_Location GROUP BY Tbl_Location.Region_Num;"    AdoRS1.Open sql1, cn1
        Do Until AdoRS1.EOF Or AdoRS1.BOF
        reg = AdoRS1!Region_Num
        dirname = "C:\pdf_Docs\company\R" & reg
        MkDir dirname
        
            sql2 = "SELECT Tbl_Location.Reg_Num FROM Tbl_Location WHERE (((Tbl_Location.Region_Num)=" & reg & ")) GROUP BY Tbl_Location.Reg_Num;"
            AdoRS2.Open sql2, cn2
            
                Do Until AdoRS2.EOF Or AdoRS2.BOF
                gro = AdoRS2!Reg_Num
                dirname = "C:\pdf_Docs\company\R" & reg & "\G" & gro
                MkDir dirname
                
                        sql3 = "SELECT Tbl_Location.Dist_Num FROM Tbl_Location WHERE (((Tbl_Location.Region_Num)=" & reg & ") AND ((Tbl_Location.Reg_Num)=" & gro & ")) GROUP BY Tbl_Location.Dist_Num;"
                        AdoRS3.Open sql3, cn3
                        
                            Do Until AdoRS3.EOF Or AdoRS3.BOF
                            dis = AdoRS3!Dist_Num
                            dirname = "C:\pdf_Docs\company\R" & reg & "\G" & gro & "\D" & dis
                            MkDir dirname
                            
                                    sql4 = "SELECT Tbl_Location.Store FROM Tbl_Location WHERE (((Tbl_Location.Region_Num)=" & reg & ") AND ((Tbl_Location.Reg_Num)=" & gro & ") AND  (Tbl_Location.Dist_Num)=" & dis & ")) GROUP BY Tbl_Location.Store;"
                                    AdoRS4.Open sql4, cn4
                                    
                                        Do Until AdoRS4.EOF Or AdoRS4.BOF
                                        sto = AdoRS4!Dist_Num
                                        sto = Format(sto, "0000")
                                        dirname = "C:\pdf_Docs\company\R" & reg & "\G" & gro & "\D" & dis & "\T" & sto
                                        MkDir dirname
                                        
                                        AdoRS1.MoveNext
                                        Loop
                        AdoRS1.MoveNext
                        Loop
                AdoRS1.MoveNext
                Loop
        AdoRS1.MoveNext
        Loop
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Not sure what the problem is, you've already opened four record sets in the code, ( which is obviously not the complete code )....

so i don't understand what you mean?
 
Upvote 0

Forum statistics

Threads
1,203,172
Messages
6,053,888
Members
444,692
Latest member
Queendom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top