Solved

Problem updating recordset

Posted on 2014-12-04
8
172 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
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server views 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 Access…
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 …

726 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