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

x
?
Solved

ms access runtime error 3709....it is either closed or invalid in this context

Posted on 2013-11-27
7
Medium Priority
?
986 Views
Last Modified: 2013-11-27
Hi All,

I am trying to select more than 1 record from a table (if any records exist that is). Then insert part of this record into another table along with an extra value.

The code i am using is below but i keep getting the "runtime error 3709....it is either closed or invalid in this context"

Dim rs As ADODB.Recordset
        Set rs = New ADODB.Recordset
       
        rs.Open "SELECT tblQuotes_Endts.Endt_ID FROM tblQuotes_Endts " & _
        "WHERE tblQuotes_Endts.IFAPrem_ID = " & Forms!frmQuote_Update!txtIFAPremID & ", CurrentProject.Connection, adOpenStatic"
       
        Dim strSQL As String
       
        If Not rs.EOF Then
            Set rs = New ADODB.Recordset
            Do Until rs.EOF
                strSQL = "INSERT INTO tblPolicies_Endts (Policy_ID, Endt_ID) " & _
                "VALUES (" & Me.txtPolicyID & ", " & rs.Fields.Item("Endt_ID").Value & ")"
                CurrentDb.Execute strSQL, dbFailOnError ' dbSeeChanges
            rs.MoveNext
            Loop
        End If
       
        rs.Close
        Set rs = Nothing

Any suggestions would be gratefully received
0
Comment
Question by:andrewpiconnect
[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
  • 3
  • 3
7 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39681623
which line is raising the error ?


        If Not rs.EOF Then

'            Set rs = New ADODB.Recordset    ' Remove this line and  run the codes


            Do Until rs.EOF
                strSQL = "INSERT INTO tblPolicies_Endts (Policy_ID, Endt_ID) " & _
                "VALUES (" & Me.txtPolicyID & ", " & rs!Endt_ID & ")"
                CurrentDb.Execute strSQL, dbFailOnError ' dbSeeChanges
            rs.MoveNext
            Loop
        End If
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 39681635
I assume you are getting the error here:

=> strSQL = "INSERT INTO tblPolicies_Endts (Policy_ID, Endt_ID) " _
                  & "VALUES (" & Me.txtPolicyID & ", " & rs.Fields.Item("Endt_ID").Value & ")"

This is most likely due to your reinstantiating the "rs" recordset variable.  Try:
Dim rs As ADODB.Recordset
     Set rs = New ADODB.Recordset
       
     rs.Open "SELECT tblQuotes_Endts.Endt_ID FROM tblQuotes_Endts " _
           & "WHERE tblQuotes_Endts.IFAPrem_ID = " & Forms!frmQuote_Update!txtIFAPremID
           & ", CurrentProject.Connection, adOpenStatic"
       
     Dim strSQL As String
       
     While Not rs.EOF

           strSQL = "INSERT INTO tblPolicies_Endts (Policy_ID, Endt_ID) " _
                  & "VALUES (" & Me.txtPolicyID & ", " & rs.Fields.Item("Endt_ID").Value & ")"
           CurrentDb.Execute strSQL, dbFailOnError ' dbSeeChanges
           rs.MoveNext
   
     Wend
       
     rs.Close
     Set rs = Nothing

Open in new window

0
 

Author Comment

by:andrewpiconnect
ID: 39681900
Hi Guys,

Neither of your options worked unfortunately.

I am getting the error here if it helps?

rs.Open "SELECT tblQuotes_Endts.Endt_ID FROM tblQuotes_Endts " _
           & "WHERE tblQuotes_Endts.IFAPrem_ID = " & Forms!frmQuote_Update!txtIFAPremID
           & ", CurrentProject.Connection, adOpenStatic"
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39681910
is the FORM "frmQuote_Update"  open when your running the codes


try this first

rs.Open "SELECT tblQuotes_Endts.Endt_ID FROM tblQuotes_Endts " _
           & "WHERE tblQuotes_Endts.IFAPrem_ID = " & Forms!frmQuote_Update!txtIFAPremID,  CurrentProject.Connection, adOpenStatic"


if the field "IFAPrem_ID" is Text data type, use this

rs.Open "SELECT tblQuotes_Endts.Endt_ID FROM tblQuotes_Endts " _
           & "WHERE tblQuotes_Endts.IFAPrem_ID = '" & Forms!frmQuote_Update!txtIFAPremID
           & "'", CurrentProject.Connection, adOpenStatic"
0
 

Author Comment

by:andrewpiconnect
ID: 39682110
yep, the form "frmQuote_Update" is open and the control txtIFAPremID is a number and is visible on that form, so i know it is there ready for collection.

i have checked and rechecked the table names and fields to make sure i have not misspelled anything.

The error keeps suggesting the connection is either closed or invalid for some strange reason
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 39682122
try this, copy and paste

rs.Open "SELECT tblQuotes_Endts.Endt_ID FROM tblQuotes_Endts " _
           & "WHERE tblQuotes_Endts.IFAPrem_ID = " & Forms!frmQuote_Update!txtIFAPremID,  CurrentProject.Connection, adOpenStatic



i remove the quote at the end of the statement  adOpenStatic"


if that does not work, upload a copy of the db
0
 

Author Closing Comment

by:andrewpiconnect
ID: 39682207
SUCCESSSSSSSSSS!!!!!!!

i have been stuck on this for a cpl of hours and it turns out to be a simple removal of a quote sign.

Thank you so so much!!!!

Phewwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

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