Solved

Problem updating recordset

Posted on 2014-12-04
8
168 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
  • 4
  • 4
8 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:Jeanne Elmuccio
Comment Utility
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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
oK, ...so you can really now accept your own post as the solution.
;-)

Jeff
0
 

Author Closing Comment

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

Featured Post

Backup Your Microsoft Windows Server®

Backup 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.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

743 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

8 Experts available now in Live!

Get 1:1 Help Now