Solved

Looping through continuous form

Posted on 2010-08-18
9
317 Views
Last Modified: 2013-11-28
I'm trying to have my code open a recordset from a continuous form, run 3 queries which use forms order number as the parameter, then move on to the next record; however, my code is not working - error says cannot find the input table or query "F_table1".  This is a form not a table or query.  How do I force the code to use the form for it's looping?

Function loopthrough()
Dim db As DAO.Database
Dim rs1 As DAO.Recordset

 
    Set db = CurrentDb()
    DoCmd.OpenForm "F_Table1"
    Set rs1 = db.OpenRecordset("[F_Table1]")
    str1 = "Q_UpdateCalcSheet1"
    str2 = "Q_UpdateCalcSheet2"
    str3 = "Q_UpdateCalcSheet3"
   
    rs1.MoveFirst
    Do Until rs1.EOF
   
DoCmd.OpenQuery str1
DoCmd.OpenQuery str2
DoCmd.OpenQuery str3

           
            Loop
 
    rs.Close
    Set rs = Nothing
    Set db = Nothing
 
End Function
0
Comment
Question by:mssbass
  • 5
  • 4
9 Comments
 
LVL 1

Expert Comment

by:Stormspace
ID: 33466751
Are these queries in the DB?

    str1 = "Q_UpdateCalcSheet1"
    str2 = "Q_UpdateCalcSheet2"
    str3 = "Q_UpdateCalcSheet3"
0
 

Author Comment

by:mssbass
ID: 33467088
yes - those are the queries that use the order number in the continous form as a parameter.
0
 
LVL 1

Expert Comment

by:Stormspace
ID: 33467123
May be unrelated but you are never closing the recordset. These two lines

rs.Close
Set rs = Nothing

should be

rs1.Close
Set rs1 = Nothing

Also, are displaying the results of the query's on a form or a report?
0
 

Author Comment

by:mssbass
ID: 33467709
   str1 = "Q_UpdateCalcSheet1" - Make table query
    str2 = "Q_UpdateCalcSheet2" - Make table query
    str3 = "Q_UpdateCalcSheet3" - Update query
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:mssbass
ID: 33467933
The queries use the parameter that shows up on the continous form for order #
0
 
LVL 1

Accepted Solution

by:
Stormspace earned 250 total points
ID: 33468400
So the code opens the form, which has the parameter already in it, then the code continues to execute the queries using the field on the form to parse the data.

I think the issue is here:
Set rs1 = db.OpenRecordset("[F_Table1]")

If I'm understanding correctly F_Table1 is a form and you are trying to open it as a table.
0
 
LVL 1

Expert Comment

by:Stormspace
ID: 33468421
On other thing, have you tried stepping through the code using "F8" to see exactly which line is causeing the error?
0
 

Author Comment

by:mssbass
ID: 33468714
I have figured it out; however, the code locks up if I try to do anything else on my computer:


Function loopthrough()
Dim db As DAO.Database
Dim rstsubform As DAO.Recordset

    Set db = CurrentDb()
    Set rstsubform = Forms!f_table1.Form.Recordset
   
   
    str1 = "Q_UpdateCalcSheet1"
    str2 = "Q_UpdateCalcSheet2"
    str3 = "Q_UpdateCalcSheet3"
    str4 = "Q_UpdateCalcSheet4"

   rstsubform.MoveFirst
    Do While Not rstsubform.EOF
   
DoCmd.OpenQuery str1
DoCmd.OpenQuery str2
DoCmd.OpenQuery str3
DoCmd.OpenQuery str4

rstsubform.MoveNext
           
            Loop
rstsubform.Close
Set rstsubform = Nothing
 
End Function
0
 
LVL 1

Expert Comment

by:Stormspace
ID: 33469162
Probably because the form has to have focus, but I'm just guessing.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now