Solved

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

Posted on 2013-11-27
7
949 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 119

Expert Comment

by:Rey Obrero
Comment Utility
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 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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
Comment Utility
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 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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
Comment Utility
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

16 Experts available now in Live!

Get 1:1 Help Now