Solved

Looping through continuous form

Posted on 2010-08-18
9
320 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

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…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

832 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