Solved

Problem updating recordset

Posted on 2014-12-04
8
170 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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…
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…
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…

810 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