Solved

Looping through continuous form

Posted on 2010-08-18
9
318 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

937 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

10 Experts available now in Live!

Get 1:1 Help Now