Solved

Looping through continuous form

Posted on 2010-08-18
9
321 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

821 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