Solved

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

Posted on 2013-11-27
7
967 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 47

Expert Comment

by:Dale Fye (Access MVP)
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
Technology Partners: 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!

 
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 500 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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
IIF syntax in MS Access 1 63
MS Access Combobox to Disable Controls on a Separate Form 10 26
Launch Outlook minimized 6 31
Error 438 6 16
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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