Access Vba - How to set the current record of a recordset to an other recordset





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I fetch a recordset



Do while not recset.eof 
Recset.movenext
Loop


and want to set the current record of the recordset to an other recordset with vba



Set rec2 = rec1.????


I tried



Set.Rec2 = recset.bookmark


But no success!
I hope there is a way to set the current record to an other recordset easely



Thanks for your help










share|improve this question































    0















    I fetch a recordset



    Do while not recset.eof 
    Recset.movenext
    Loop


    and want to set the current record of the recordset to an other recordset with vba



    Set rec2 = rec1.????


    I tried



    Set.Rec2 = recset.bookmark


    But no success!
    I hope there is a way to set the current record to an other recordset easely



    Thanks for your help










    share|improve this question



























      0












      0








      0








      I fetch a recordset



      Do while not recset.eof 
      Recset.movenext
      Loop


      and want to set the current record of the recordset to an other recordset with vba



      Set rec2 = rec1.????


      I tried



      Set.Rec2 = recset.bookmark


      But no success!
      I hope there is a way to set the current record to an other recordset easely



      Thanks for your help










      share|improve this question
















      I fetch a recordset



      Do while not recset.eof 
      Recset.movenext
      Loop


      and want to set the current record of the recordset to an other recordset with vba



      Set rec2 = rec1.????


      I tried



      Set.Rec2 = recset.bookmark


      But no success!
      I hope there is a way to set the current record to an other recordset easely



      Thanks for your help







      access-vba recordset






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 23:16







      informer

















      asked Nov 16 '18 at 23:08









      informerinformer

      236




      236
























          2 Answers
          2






          active

          oldest

          votes


















          0














          There are numerous options, but without knowing your exact goal it's hard to know which one is best for you.



          One option is opening up a recordsetclone:



          Set rec2 = rec1.RecordsetClone 'Open a clone
          rec2.Bookmark = rec1.Bookmark 'Move the clone to the same record


          In that case, rec2 contains all data rec1 has, but is set to the same record.



          Another option is using a filter:



          rec1.Filter = "ID = " & rec1!ID 'Set a filter to the current record, assumes ID = primary key
          Set rec2 = rec1.OpenRecordset 'Set rec2 to the filtered result, rec1 is still unfiltered





          share|improve this answer
























          • I need to export on excel file the current record and hoped that it's possible to do this without use filtrer

            – informer
            Nov 17 '18 at 7:55











          • Nope, creating a recordset with only the currently selected record is not possible without a filter (unless you're willing to create a second, unbound adodb recordset)

            – Erik A
            Nov 17 '18 at 11:02











          • So only one issue, fetch on record fields with recordset.fields(i). Thanks for your help.

            – informer
            Nov 17 '18 at 20:13



















          0














          My goal was export the current record of a recordset to Excel file. As written by Eric, it's impossible to set the current record to another recordset.



          But copyFromRecordset has very interesting properties for solve my issue as you can see below
          CopyFromRecordset RecordSet , MaxRows , MaxColumns Full description here



          So I tested this code and It works great



              Dim oRecSet As Recordset, oRecSetClone As Recordset
          Dim varBookmark As Variant

          Set objExcelApp = New Excel.Application
          objExcelApp.Visible = True
          Set wb = objExcelApp.Workbooks.Open("G:Accesstest.xlsx")
          Set ws = wb.Sheets(1)


          sSQL = "SELECT * FROM tbl"
          Set oRecSet = CurrentDb.OpenRecordset(sSQL)
          Set oRecSetClone = oRecSet.Clone

          Do While Not oRecSet.EOF
          Debug.Print i
          oRecSetClone.Bookmark = oRecSet.Bookmark
          ws.Range("A" & i).CopyFromRecordset oRecSetClone, 1
          oRecSet.MoveNext
          Loop

          End Sub


          Just one comment



          I use bookmark because I noticed a strange behaviour when I Apply copyFromRecordSet rec,1.
          After this command, rec.movenext generates an error message: Nbr 3021 - No current record






          share|improve this answer


























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346546%2faccess-vba-how-to-set-the-current-record-of-a-recordset-to-an-other-recordset%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            There are numerous options, but without knowing your exact goal it's hard to know which one is best for you.



            One option is opening up a recordsetclone:



            Set rec2 = rec1.RecordsetClone 'Open a clone
            rec2.Bookmark = rec1.Bookmark 'Move the clone to the same record


            In that case, rec2 contains all data rec1 has, but is set to the same record.



            Another option is using a filter:



            rec1.Filter = "ID = " & rec1!ID 'Set a filter to the current record, assumes ID = primary key
            Set rec2 = rec1.OpenRecordset 'Set rec2 to the filtered result, rec1 is still unfiltered





            share|improve this answer
























            • I need to export on excel file the current record and hoped that it's possible to do this without use filtrer

              – informer
              Nov 17 '18 at 7:55











            • Nope, creating a recordset with only the currently selected record is not possible without a filter (unless you're willing to create a second, unbound adodb recordset)

              – Erik A
              Nov 17 '18 at 11:02











            • So only one issue, fetch on record fields with recordset.fields(i). Thanks for your help.

              – informer
              Nov 17 '18 at 20:13
















            0














            There are numerous options, but without knowing your exact goal it's hard to know which one is best for you.



            One option is opening up a recordsetclone:



            Set rec2 = rec1.RecordsetClone 'Open a clone
            rec2.Bookmark = rec1.Bookmark 'Move the clone to the same record


            In that case, rec2 contains all data rec1 has, but is set to the same record.



            Another option is using a filter:



            rec1.Filter = "ID = " & rec1!ID 'Set a filter to the current record, assumes ID = primary key
            Set rec2 = rec1.OpenRecordset 'Set rec2 to the filtered result, rec1 is still unfiltered





            share|improve this answer
























            • I need to export on excel file the current record and hoped that it's possible to do this without use filtrer

              – informer
              Nov 17 '18 at 7:55











            • Nope, creating a recordset with only the currently selected record is not possible without a filter (unless you're willing to create a second, unbound adodb recordset)

              – Erik A
              Nov 17 '18 at 11:02











            • So only one issue, fetch on record fields with recordset.fields(i). Thanks for your help.

              – informer
              Nov 17 '18 at 20:13














            0












            0








            0







            There are numerous options, but without knowing your exact goal it's hard to know which one is best for you.



            One option is opening up a recordsetclone:



            Set rec2 = rec1.RecordsetClone 'Open a clone
            rec2.Bookmark = rec1.Bookmark 'Move the clone to the same record


            In that case, rec2 contains all data rec1 has, but is set to the same record.



            Another option is using a filter:



            rec1.Filter = "ID = " & rec1!ID 'Set a filter to the current record, assumes ID = primary key
            Set rec2 = rec1.OpenRecordset 'Set rec2 to the filtered result, rec1 is still unfiltered





            share|improve this answer













            There are numerous options, but without knowing your exact goal it's hard to know which one is best for you.



            One option is opening up a recordsetclone:



            Set rec2 = rec1.RecordsetClone 'Open a clone
            rec2.Bookmark = rec1.Bookmark 'Move the clone to the same record


            In that case, rec2 contains all data rec1 has, but is set to the same record.



            Another option is using a filter:



            rec1.Filter = "ID = " & rec1!ID 'Set a filter to the current record, assumes ID = primary key
            Set rec2 = rec1.OpenRecordset 'Set rec2 to the filtered result, rec1 is still unfiltered






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 17 '18 at 7:24









            Erik AErik A

            20.2k62441




            20.2k62441













            • I need to export on excel file the current record and hoped that it's possible to do this without use filtrer

              – informer
              Nov 17 '18 at 7:55











            • Nope, creating a recordset with only the currently selected record is not possible without a filter (unless you're willing to create a second, unbound adodb recordset)

              – Erik A
              Nov 17 '18 at 11:02











            • So only one issue, fetch on record fields with recordset.fields(i). Thanks for your help.

              – informer
              Nov 17 '18 at 20:13



















            • I need to export on excel file the current record and hoped that it's possible to do this without use filtrer

              – informer
              Nov 17 '18 at 7:55











            • Nope, creating a recordset with only the currently selected record is not possible without a filter (unless you're willing to create a second, unbound adodb recordset)

              – Erik A
              Nov 17 '18 at 11:02











            • So only one issue, fetch on record fields with recordset.fields(i). Thanks for your help.

              – informer
              Nov 17 '18 at 20:13

















            I need to export on excel file the current record and hoped that it's possible to do this without use filtrer

            – informer
            Nov 17 '18 at 7:55





            I need to export on excel file the current record and hoped that it's possible to do this without use filtrer

            – informer
            Nov 17 '18 at 7:55













            Nope, creating a recordset with only the currently selected record is not possible without a filter (unless you're willing to create a second, unbound adodb recordset)

            – Erik A
            Nov 17 '18 at 11:02





            Nope, creating a recordset with only the currently selected record is not possible without a filter (unless you're willing to create a second, unbound adodb recordset)

            – Erik A
            Nov 17 '18 at 11:02













            So only one issue, fetch on record fields with recordset.fields(i). Thanks for your help.

            – informer
            Nov 17 '18 at 20:13





            So only one issue, fetch on record fields with recordset.fields(i). Thanks for your help.

            – informer
            Nov 17 '18 at 20:13













            0














            My goal was export the current record of a recordset to Excel file. As written by Eric, it's impossible to set the current record to another recordset.



            But copyFromRecordset has very interesting properties for solve my issue as you can see below
            CopyFromRecordset RecordSet , MaxRows , MaxColumns Full description here



            So I tested this code and It works great



                Dim oRecSet As Recordset, oRecSetClone As Recordset
            Dim varBookmark As Variant

            Set objExcelApp = New Excel.Application
            objExcelApp.Visible = True
            Set wb = objExcelApp.Workbooks.Open("G:Accesstest.xlsx")
            Set ws = wb.Sheets(1)


            sSQL = "SELECT * FROM tbl"
            Set oRecSet = CurrentDb.OpenRecordset(sSQL)
            Set oRecSetClone = oRecSet.Clone

            Do While Not oRecSet.EOF
            Debug.Print i
            oRecSetClone.Bookmark = oRecSet.Bookmark
            ws.Range("A" & i).CopyFromRecordset oRecSetClone, 1
            oRecSet.MoveNext
            Loop

            End Sub


            Just one comment



            I use bookmark because I noticed a strange behaviour when I Apply copyFromRecordSet rec,1.
            After this command, rec.movenext generates an error message: Nbr 3021 - No current record






            share|improve this answer






























              0














              My goal was export the current record of a recordset to Excel file. As written by Eric, it's impossible to set the current record to another recordset.



              But copyFromRecordset has very interesting properties for solve my issue as you can see below
              CopyFromRecordset RecordSet , MaxRows , MaxColumns Full description here



              So I tested this code and It works great



                  Dim oRecSet As Recordset, oRecSetClone As Recordset
              Dim varBookmark As Variant

              Set objExcelApp = New Excel.Application
              objExcelApp.Visible = True
              Set wb = objExcelApp.Workbooks.Open("G:Accesstest.xlsx")
              Set ws = wb.Sheets(1)


              sSQL = "SELECT * FROM tbl"
              Set oRecSet = CurrentDb.OpenRecordset(sSQL)
              Set oRecSetClone = oRecSet.Clone

              Do While Not oRecSet.EOF
              Debug.Print i
              oRecSetClone.Bookmark = oRecSet.Bookmark
              ws.Range("A" & i).CopyFromRecordset oRecSetClone, 1
              oRecSet.MoveNext
              Loop

              End Sub


              Just one comment



              I use bookmark because I noticed a strange behaviour when I Apply copyFromRecordSet rec,1.
              After this command, rec.movenext generates an error message: Nbr 3021 - No current record






              share|improve this answer




























                0












                0








                0







                My goal was export the current record of a recordset to Excel file. As written by Eric, it's impossible to set the current record to another recordset.



                But copyFromRecordset has very interesting properties for solve my issue as you can see below
                CopyFromRecordset RecordSet , MaxRows , MaxColumns Full description here



                So I tested this code and It works great



                    Dim oRecSet As Recordset, oRecSetClone As Recordset
                Dim varBookmark As Variant

                Set objExcelApp = New Excel.Application
                objExcelApp.Visible = True
                Set wb = objExcelApp.Workbooks.Open("G:Accesstest.xlsx")
                Set ws = wb.Sheets(1)


                sSQL = "SELECT * FROM tbl"
                Set oRecSet = CurrentDb.OpenRecordset(sSQL)
                Set oRecSetClone = oRecSet.Clone

                Do While Not oRecSet.EOF
                Debug.Print i
                oRecSetClone.Bookmark = oRecSet.Bookmark
                ws.Range("A" & i).CopyFromRecordset oRecSetClone, 1
                oRecSet.MoveNext
                Loop

                End Sub


                Just one comment



                I use bookmark because I noticed a strange behaviour when I Apply copyFromRecordSet rec,1.
                After this command, rec.movenext generates an error message: Nbr 3021 - No current record






                share|improve this answer















                My goal was export the current record of a recordset to Excel file. As written by Eric, it's impossible to set the current record to another recordset.



                But copyFromRecordset has very interesting properties for solve my issue as you can see below
                CopyFromRecordset RecordSet , MaxRows , MaxColumns Full description here



                So I tested this code and It works great



                    Dim oRecSet As Recordset, oRecSetClone As Recordset
                Dim varBookmark As Variant

                Set objExcelApp = New Excel.Application
                objExcelApp.Visible = True
                Set wb = objExcelApp.Workbooks.Open("G:Accesstest.xlsx")
                Set ws = wb.Sheets(1)


                sSQL = "SELECT * FROM tbl"
                Set oRecSet = CurrentDb.OpenRecordset(sSQL)
                Set oRecSetClone = oRecSet.Clone

                Do While Not oRecSet.EOF
                Debug.Print i
                oRecSetClone.Bookmark = oRecSet.Bookmark
                ws.Range("A" & i).CopyFromRecordset oRecSetClone, 1
                oRecSet.MoveNext
                Loop

                End Sub


                Just one comment



                I use bookmark because I noticed a strange behaviour when I Apply copyFromRecordSet rec,1.
                After this command, rec.movenext generates an error message: Nbr 3021 - No current record







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 18 '18 at 9:39

























                answered Nov 18 '18 at 7:25









                informerinformer

                236




                236






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346546%2faccess-vba-how-to-set-the-current-record-of-a-recordset-to-an-other-recordset%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Bressuire

                    Vorschmack

                    Quarantine