?
Solved

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

Posted on 2013-11-27
7
Medium Priority
?
993 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
  • 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 49

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

862 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