Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Looping through continuous form

Posted on 2010-08-18
9
Medium Priority
?
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mssbass
ID: 33467709
   str1 = "Q_UpdateCalcSheet1" - Make table query
    str2 = "Q_UpdateCalcSheet2" - Make table query
    str3 = "Q_UpdateCalcSheet3" - Update query
0
 

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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

636 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