Solved

Problem updating recordset

Posted on 2014-12-04
8
173 Views
Last Modified: 2014-12-11
I have a recordset open and want to update the value of a field in the current record (see code below).  However, I keep getting an "INSERT" error message.  What am I missing?  Thanks for your help. je

        Dim rsstep As Recordset
        Set rsstep = CurrentDb.OpenRecordset("tbl_report_HLQ_temp", dbOpenDynaset)
     
        rsstep.MoveFirst
           
        Do While Not rsstep.EOF
   
            rsstep.Edit

           rsstep("JCL0-template").Value = """" & ststepstring & """"
            'rsstep![JCL0-template] = """" & ststepstring & """"                                (I tried this too...)
           
            rsstep.Update

            rsstep.MoveNext
        Loop
0
Comment
Question by:Jeanne Elmuccio
[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
  • 4
  • 4
8 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40481556
Where are you declaring ststepstring and setting its value?

Quick guess, ...

Try something like this:

  Dim rsstep As Recordset
  Dim ststepstring  as String
  ststepstring ="YourText"
        Set rsstep = CurrentDb.OpenRecordset("tbl_report_HLQ_temp", dbOpenDynaset)
     
        rsstep.MoveFirst
           
        Do While Not rsstep.EOF
   
            rsstep.Edit

           rsstep("JCL0-template").Value = ststepstring
           ' Or like this:
           'rsstep![JCL0-template] = ststepstring  
           
            rsstep.Update

            rsstep.MoveNext
        Loop

Let me know if I am missing, or not understanding something...

JeffCoachman
0
 

Author Comment

by:Jeanne Elmuccio
ID: 40481790
Jeff,

Thanks for the quick resonse...  I keep getting err.number 3265

"INSERT INTO tbl_report_HLQ_temp SELECT tbl_abc.* FROM tbl_abc;"

I have no idea where it's getting that from.  The tbl_report_HLQ_temp table is populated several steps earlier by appending data from the tbl_ace table.

I am attaching the sample code....

Thanks for the help,
Je
C---SOX-Temp-2--Data-Lockdown-Issue-Anal
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40481871
I am confused...
The code you posted was using VBA to update a recordset.
The error you are reporting is as if you were using SQL to update the value...?
Furthermore, you state that you want to:
"update the value of a field in the current record
...yet the code you posted loops through all the records in the table...

Not sure abut all your code there or how it all works together.
But to update a value of the current record, a recordset is typically not required...
In any event, ...This is a simple, working example of how I "update the value of a field in the current record"
...and how to update ALL records in the table

JeffCoachman
Database41.mdb
0
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!

 

Author Comment

by:Jeanne Elmuccio
ID: 40482730
Jeff.....  yes that is the confusing thing....I am using vba code to update a recordset (or at least trying to).

I am looping through tbl_HLQ (Dim rs As Recordset) and for each record in that table I am executing several other things resulting in a report related to the tbl_HLQ record being processed.   the final step before running the report is to loop through the tbl_report_HLQ_temp table (Dim rsstep As Recordset) and update the value of the first field for each record.  So I'm not sure if the loop within a loop is causing the problem.  

Can't you have more than one recordset open at a time?  I am using different record set variables.

Thanks again for the help,
je
0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 500 total points
ID: 40483283
Then test the code on each recordset separately to verify hat each snippet works on its own.
0
 

Assisted Solution

by:Jeanne Elmuccio
Jeanne Elmuccio earned 0 total points
ID: 40483597
I was able to resolve the issue

I moved the code to a separate function -- and realzied that i did not have the dbOpenDynaset option included)

Set rsstep = CurrentDb.OpenRecordset("tbl_report_HLQ_ctlcards_temp", dbOpenDynaset)

It is working now.....

Thanks for helping me to look at the code more closely.

je
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 40483640
oK, ...so you can really now accept your own post as the solution.
;-)

Jeff
0
 

Author Closing Comment

by:Jeanne Elmuccio
ID: 40493430
Isolating the code allowed a closer look at the statements.  Including the dbOpenDynaset option resolved the problem.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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…
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.

717 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