Requery, Return to record

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MS

    Requery, Return to record

    Access 97

    I want to requery the data being displayed on a form, then I want to return
    to the record I was in.

    Why doesn't this code work?



    Private Sub CmdRefsh_Click( )
    Dim RecId As Integer

    RecId = Me.TxtID
    Me.Requery

    With Me.RecordsetClo ne
    .FindFirst "[ID] = " & RecId
    End With

    End Sub




    Any help?

    Thnaks!


  • lauren quantrell

    #2
    Re: Requery, Return to record

    Try this:

    Dim RecId As Integer
    RecId = Me.TxtID
    Me.Requery

    With me.RecordsetClo ne
    .FindFirst "ID" & "=" & RecId
    me.Bookmark = .Bookmark
    me.RecordsetClo ne.Close
    End With





    MS wrote:[color=blue]
    > Access 97
    >
    > I want to requery the data being displayed on a form, then I want to[/color]
    return[color=blue]
    > to the record I was in.
    >
    > Why doesn't this code work?
    >
    >
    >
    > Private Sub CmdRefsh_Click( )
    > Dim RecId As Integer
    >
    > RecId = Me.TxtID
    > Me.Requery
    >
    > With Me.RecordsetClo ne
    > .FindFirst "[ID] = " & RecId
    > End With
    >
    > End Sub
    >
    >
    >
    >
    > Any help?
    >
    > Thnaks![/color]

    Comment

    • MS

      #3
      Re: Requery, Return to record


      "lauren quantrell" <laurenquantrel l@hotmail.com> wrote in message
      news:1109818071 .223068.110930@ l41g2000cwc.goo glegroups.com.. .[color=blue]
      > Try this:
      >
      > Dim RecId As Integer
      > RecId = Me.TxtID
      > Me.Requery
      >
      > With me.RecordsetClo ne
      > .FindFirst "ID" & "=" & RecId
      > me.Bookmark = .Bookmark
      > me.RecordsetClo ne.Close
      > End With[/color]


      Perfect!

      Thanks :-)


      Comment

      • Neil

        #4
        Re: Requery, Return to record

        You don't want to close recordsetclone. Since you don't open recordsetclone,
        you don't need to close it.

        Neil

        "lauren quantrell" <laurenquantrel l@hotmail.com> wrote in message
        news:1109818071 .223068.110930@ l41g2000cwc.goo glegroups.com.. .[color=blue]
        > Try this:
        >
        > Dim RecId As Integer
        > RecId = Me.TxtID
        > Me.Requery
        >
        > With me.RecordsetClo ne
        > .FindFirst "ID" & "=" & RecId
        > me.Bookmark = .Bookmark
        > me.RecordsetClo ne.Close
        > End With
        >
        >
        >
        >
        >
        > MS wrote:[color=green]
        >> Access 97
        >>
        >> I want to requery the data being displayed on a form, then I want to[/color]
        > return[color=green]
        >> to the record I was in.
        >>
        >> Why doesn't this code work?
        >>
        >>
        >>
        >> Private Sub CmdRefsh_Click( )
        >> Dim RecId As Integer
        >>
        >> RecId = Me.TxtID
        >> Me.Requery
        >>
        >> With Me.RecordsetClo ne
        >> .FindFirst "[ID] = " & RecId
        >> End With
        >>
        >> End Sub
        >>
        >>
        >>
        >>
        >> Any help?
        >>
        >> Thnaks![/color]
        >[/color]


        Comment

        • PC Datasheet

          #5
          Re: Requery, Return to record

          Suggest you dim RecID as Long. Integer only goes to 32,000. If you have more
          records than that, the code won't work. Long goes to 2 trillion.

          --
          PC Datasheet
          Your Resource For Help With Access, Excel And Word Applications
          resource@pcdata sheet.com



          "MS" <Email@Myemail. com> wrote in message
          news:FkvVd.1818 56$K7.45890@new s-server.bigpond. net.au...[color=blue]
          >
          > "lauren quantrell" <laurenquantrel l@hotmail.com> wrote in message
          > news:1109818071 .223068.110930@ l41g2000cwc.goo glegroups.com.. .[color=green]
          > > Try this:
          > >
          > > Dim RecId As Integer
          > > RecId = Me.TxtID
          > > Me.Requery
          > >
          > > With me.RecordsetClo ne
          > > .FindFirst "ID" & "=" & RecId
          > > me.Bookmark = .Bookmark
          > > me.RecordsetClo ne.Close
          > > End With[/color]
          >
          >
          > Perfect!
          >
          > Thanks :-)
          >
          >[/color]


          Comment

          • MS

            #6
            Re: Requery, Return to record


            "PC Datasheet" <nospam@nospam. spam> wrote in message
            news:YAvVd.4530 $wy3.3348@newsr ead3.news.atl.e arthlink.net...[color=blue]
            > Suggest you dim RecID as Long. Integer only goes to 32,000. If you have
            > more
            > records than that, the code won't work. Long goes to 2 trillion.
            >[/color]


            Thanks for that.

            Now, my code is.....

            Private Sub CmdRefsh_Click( )
            On Error GoTo Err_CmdRef

            Dim RecId As Long

            RecId = Me.TxtID

            Me.Requery

            With Me.RecordsetClo ne
            .FindFirst "ID" & "=" & RecId
            Me.Bookmark = .Bookmark
            End With

            Exit_CmdRef:
            Exit Sub

            Err_CmdRef:
            MsgBox Err.Description & ". Moving to first record"

            Resume Exit_CmdRef
            End Sub


            It works fine, except if I'm in the first record. If I run it while in the
            first record on the form, it "returns" to that record, but then I get an
            error (end of recordset) if I try to navigate to the next record.

            Any ideas



            Comment

            • Neil

              #7
              Re: Requery, Return to record

              In what way are you "navigating " to the next record? This code ends when it
              returns you to the original record. You must be navigating through some
              other means. If it's with the navigation buttons at the bottom of the form,
              then you should go to the "new" record. If you're using a custom navigation
              button, then the problem is probably there, and you should post the code
              used there. But this code ends when it takes you back to the original
              record, and, from what I understand, that part's working fine.

              By the way, you can change:

              .FindFirst "ID" & "=" & RecId

              to simply:

              .FindFirst "ID=" & RecId

              Neil


              "MS" <Email@Myemail. com> wrote in message
              news:28wVd.1820 09$K7.10105@new s-server.bigpond. net.au...[color=blue]
              >
              > "PC Datasheet" <nospam@nospam. spam> wrote in message
              > news:YAvVd.4530 $wy3.3348@newsr ead3.news.atl.e arthlink.net...[color=green]
              >> Suggest you dim RecID as Long. Integer only goes to 32,000. If you have
              >> more
              >> records than that, the code won't work. Long goes to 2 trillion.
              >>[/color]
              >
              >
              > Thanks for that.
              >
              > Now, my code is.....
              >
              > Private Sub CmdRefsh_Click( )
              > On Error GoTo Err_CmdRef
              >
              > Dim RecId As Long
              >
              > RecId = Me.TxtID
              >
              > Me.Requery
              >
              > With Me.RecordsetClo ne
              > .FindFirst "ID" & "=" & RecId
              > Me.Bookmark = .Bookmark
              > End With
              >
              > Exit_CmdRef:
              > Exit Sub
              >
              > Err_CmdRef:
              > MsgBox Err.Description & ". Moving to first record"
              >
              > Resume Exit_CmdRef
              > End Sub
              >
              >
              > It works fine, except if I'm in the first record. If I run it while in the
              > first record on the form, it "returns" to that record, but then I get an
              > error (end of recordset) if I try to navigate to the next record.
              >
              > Any ideas
              >
              >
              >[/color]


              Comment

              • lauren quantrell

                #8
                Re: Requery, Return to record

                I sent you the code "ID" & "=" & recID only because I do this sort of
                thing from a public function where I re-use the code for many different
                forms where I need the functionality to return to the selected record
                before a requery:

                For example, on the form I may have an On_Click procedure that opens
                something, something like this:

                Private Sub CmdRefsh_Click( )
                Dim myID as long
                myID = me.RecID

                'run some code here that plays with the record, then requeries the
                records...

                Call ReturnAfterRequ ery(me.formname ,"RecID",myI D)

                End Sub

                ' put the function below in a module which can then be called from any
                form:

                Function ReturnAfterRequ ery(myFormName as String, myFieldName as
                String, myID as Long)

                'myID is the currently selected record
                'myFieldName is the name of the ID field of the recordset that will be
                requeried
                'myFormName is the name of the form that is being requeried

                Me.Requery
                With Forms(myFormNam e).RecordsetClo ne
                Forms(myFormNam e).FindFirst myFieldName & "=" & myID
                Forms(myFormNam e).Bookmark = .Bookmark
                End With
                End function




                Neil wrote:[color=blue]
                > In what way are you "navigating " to the next record? This code ends[/color]
                when it[color=blue]
                > returns you to the original record. You must be navigating through[/color]
                some[color=blue]
                > other means. If it's with the navigation buttons at the bottom of the[/color]
                form,[color=blue]
                > then you should go to the "new" record. If you're using a custom[/color]
                navigation[color=blue]
                > button, then the problem is probably there, and you should post the[/color]
                code[color=blue]
                > used there. But this code ends when it takes you back to the original[/color]
                [color=blue]
                > record, and, from what I understand, that part's working fine.
                >
                > By the way, you can change:
                >
                > .FindFirst "ID" & "=" & RecId
                >
                > to simply:
                >
                > .FindFirst "ID=" & RecId
                >
                > Neil
                >
                >
                > "MS" <Email@Myemail. com> wrote in message
                > news:28wVd.1820 09$K7.10105@new s-server.bigpond. net.au...[color=green]
                > >
                > > "PC Datasheet" <nospam@nospam. spam> wrote in message
                > > news:YAvVd.4530 $wy3.3348@newsr ead3.news.atl.e arthlink.net...[color=darkred]
                > >> Suggest you dim RecID as Long. Integer only goes to 32,000. If you[/color][/color][/color]
                have[color=blue][color=green][color=darkred]
                > >> more
                > >> records than that, the code won't work. Long goes to 2 trillion.
                > >>[/color]
                > >
                > >
                > > Thanks for that.
                > >
                > > Now, my code is.....
                > >
                > > Private Sub CmdRefsh_Click( )
                > > On Error GoTo Err_CmdRef
                > >
                > > Dim RecId As Long
                > >
                > > RecId = Me.TxtID
                > >
                > > Me.Requery
                > >
                > > With Me.RecordsetClo ne
                > > .FindFirst "ID" & "=" & RecId
                > > Me.Bookmark = .Bookmark
                > > End With
                > >
                > > Exit_CmdRef:
                > > Exit Sub
                > >
                > > Err_CmdRef:
                > > MsgBox Err.Description & ". Moving to first record"
                > >
                > > Resume Exit_CmdRef
                > > End Sub
                > >
                > >
                > > It works fine, except if I'm in the first record. If I run it while[/color][/color]
                in the[color=blue][color=green]
                > > first record on the form, it "returns" to that record, but then I[/color][/color]
                get an[color=blue][color=green]
                > > error (end of recordset) if I try to navigate to the next record.
                > >
                > > Any ideas
                > >
                > >
                > >[/color][/color]

                Comment

                • lauren quantrell

                  #9
                  Re: Requery, Return to record

                  Oops,
                  I saw it as it was saving...
                  Tahe out the "Me.requery ."
                  It should read:

                  Function ReturnAfterRequ ery(myFormName as String, myFieldName as
                  String, myID as Long)

                  'myID is the currently selected record
                  'myFieldName is the name of the ID field of the recordset that will be
                  requeried
                  'myFormName is the name of the form that is being requeried

                  With Forms(myFormNam e).RecordsetClo ne
                  Forms(myFormNam e).FindFirst myFieldName & "=" & myID
                  Forms(myFormNam e).Bookmark = .Bookmark
                  End With
                  End function



                  lauren quantrell wrote:[color=blue]
                  > I sent you the code "ID" & "=" & recID only because I do this sort of
                  > thing from a public function where I re-use the code for many[/color]
                  different[color=blue]
                  > forms where I need the functionality to return to the selected record
                  > before a requery:
                  >
                  > For example, on the form I may have an On_Click procedure that opens
                  > something, something like this:
                  >
                  > Private Sub CmdRefsh_Click( )
                  > Dim myID as long
                  > myID = me.RecID
                  >
                  > 'run some code here that plays with the record, then requeries the
                  > records...
                  >
                  > Call ReturnAfterRequ ery(me.formname ,"RecID",myI D)
                  >
                  > End Sub
                  >
                  > ' put the function below in a module which can then be called from[/color]
                  any[color=blue]
                  > form:
                  >
                  > Function ReturnAfterRequ ery(myFormName as String, myFieldName as
                  > String, myID as Long)
                  >
                  > 'myID is the currently selected record
                  > 'myFieldName is the name of the ID field of the recordset that will[/color]
                  be[color=blue]
                  > requeried
                  > 'myFormName is the name of the form that is being requeried
                  >
                  > Me.Requery
                  > With Forms(myFormNam e).RecordsetClo ne
                  > Forms(myFormNam e).FindFirst myFieldName & "=" & myID
                  > Forms(myFormNam e).Bookmark = .Bookmark
                  > End With
                  > End function
                  >
                  >
                  >
                  >
                  > Neil wrote:[color=green]
                  > > In what way are you "navigating " to the next record? This code ends[/color]
                  > when it[color=green]
                  > > returns you to the original record. You must be navigating through[/color]
                  > some[color=green]
                  > > other means. If it's with the navigation buttons at the bottom of[/color][/color]
                  the[color=blue]
                  > form,[color=green]
                  > > then you should go to the "new" record. If you're using a custom[/color]
                  > navigation[color=green]
                  > > button, then the problem is probably there, and you should post the[/color]
                  > code[color=green]
                  > > used there. But this code ends when it takes you back to the[/color][/color]
                  original[color=blue]
                  >[color=green]
                  > > record, and, from what I understand, that part's working fine.
                  > >
                  > > By the way, you can change:
                  > >
                  > > .FindFirst "ID" & "=" & RecId
                  > >
                  > > to simply:
                  > >
                  > > .FindFirst "ID=" & RecId
                  > >
                  > > Neil
                  > >
                  > >
                  > > "MS" <Email@Myemail. com> wrote in message
                  > > news:28wVd.1820 09$K7.10105@new s-server.bigpond. net.au...[color=darkred]
                  > > >
                  > > > "PC Datasheet" <nospam@nospam. spam> wrote in message
                  > > > news:YAvVd.4530 $wy3.3348@newsr ead3.news.atl.e arthlink.net...
                  > > >> Suggest you dim RecID as Long. Integer only goes to 32,000. If[/color][/color][/color]
                  you[color=blue]
                  > have[color=green][color=darkred]
                  > > >> more
                  > > >> records than that, the code won't work. Long goes to 2 trillion.
                  > > >>
                  > > >
                  > > >
                  > > > Thanks for that.
                  > > >
                  > > > Now, my code is.....
                  > > >
                  > > > Private Sub CmdRefsh_Click( )
                  > > > On Error GoTo Err_CmdRef
                  > > >
                  > > > Dim RecId As Long
                  > > >
                  > > > RecId = Me.TxtID
                  > > >
                  > > > Me.Requery
                  > > >
                  > > > With Me.RecordsetClo ne
                  > > > .FindFirst "ID" & "=" & RecId
                  > > > Me.Bookmark = .Bookmark
                  > > > End With
                  > > >
                  > > > Exit_CmdRef:
                  > > > Exit Sub
                  > > >
                  > > > Err_CmdRef:
                  > > > MsgBox Err.Description & ". Moving to first record"
                  > > >
                  > > > Resume Exit_CmdRef
                  > > > End Sub
                  > > >
                  > > >
                  > > > It works fine, except if I'm in the first record. If I run it[/color][/color][/color]
                  while[color=blue]
                  > in the[color=green][color=darkred]
                  > > > first record on the form, it "returns" to that record, but then I[/color][/color]
                  > get an[color=green][color=darkred]
                  > > > error (end of recordset) if I try to navigate to the next record.
                  > > >
                  > > > Any ideas
                  > > >
                  > > >
                  > > >[/color][/color][/color]

                  Comment

                  • Tim Marshall

                    #10
                    Re: Requery, Return to record

                    Neil wrote:
                    [color=blue]
                    > You don't want to close recordsetclone. Since you don't open recordsetclone,
                    > you don't need to close it.[/color]

                    Exactly.

                    Also, if you have any other code that uses recordsetclone without a
                    requery, keep in mind that the bookmark for recordsetclone stays where
                    you last left off in .findfirst. If on the next time you use
                    recordsetclone to search for something, if the next record is BEFORE the
                    last, the findfirst starts where it last left off and goes to eof and
                    you won't find it.

                    For any use of a recordsetclone, it might be good practice to add in a
                    ..movefirst at ythe end of your procedure, just in case.

                    In MS's case, since s/he is requerying before using recordsetclone, the
                    recordsetclone is reconstructed and starts at the beginning anyway.
                    But, IMO, it's still good practice to "reset" and .movefirst. I find
                    rsclones to be very useful sometimes.
                    --
                    Tim http://www.ucs.mun.ca/~tmarshal/
                    ^o<
                    /#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
                    /^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me

                    Comment

                    • MS

                      #11
                      Re: Requery, Return to record


                      "Neil" <njones@pxdy.co m> wrote in message
                      news:aQCVd.37$c N6.23@newsread1 .news.pas.earth link.net...[color=blue]
                      > In what way are you "navigating " to the next record? This code ends when
                      > it returns you to the original record. You must be navigating through some
                      > other means. If it's with the navigation buttons at the bottom of the
                      > form, then you should go to the "new" record. If you're using a custom
                      > navigation button, then the problem is probably there, and you should post
                      > the code used there. But this code ends when it takes you back to the
                      > original record, and, from what I understand, that part's working fine.[/color]


                      Thanks.

                      I have several custom nav buttons.

                      I think the "problem" may be with the way my "requery" code "bookmarks" .

                      Two of the most pertinent buttons are thus.......


                      Private Sub CmdNxtRec_Click ()
                      On Error GoTo Err_CmdNxtRec_C lick


                      DoCmd.GoToRecor d , , acNext
                      Dim IntNewrec As Integer

                      IntNewrec = Me.NewRecord
                      If IntNewrec = True Then
                      MsgBox "End of Data File. " _
                      & "Returning to last record. " _
                      & "To create new record, click ""New Record"" "
                      DoCmd.GoToRecor d , , acFirst

                      Dim rst As Recordset
                      Set rst = CurrentDb.OpenR ecordset("QryPa tientInfo", dbOpenDynaset)
                      rst.Requery
                      rst.MoveLast
                      rst.Delete
                      rst.Requery
                      rst.Close
                      Me.Requery
                      DoCmd.GoToRecor d , , acLast
                      End If

                      Exit_CmdNxtRec_ Click:
                      Exit Sub

                      Err_CmdNxtRec_C lick:
                      MsgBox Err.Description
                      Resume Exit_CmdNxtRec_ Click

                      End Sub



                      And............ ...



                      Private Sub CmdPrvRec_Click ()
                      On Error GoTo Err_CmdPrvRec_C lick

                      DoCmd.GoToRecor d , , acPrevious

                      Exit_CmdPrvRec_ Click:
                      Exit Sub

                      Err_CmdPrvRec_C lick:
                      MsgBox Err.Description
                      Resume Exit_CmdPrvRec_ Click
                      End Sub

                      They seem pretty "harmless" to me.

                      It's wierd how, if I run my "requery" code from the first record, my "move
                      next" code will not work - yet if I run it from a record in the middle, it's
                      fine.

                      BTW, I experimented with this to requery, and return to the record I
                      "requeried" from ..........

                      Private Sub Private Sub CmdRefsh()
                      'on error here
                      Dim RecID As String

                      RecID = Me.TxtID
                      Me.Requery
                      Me.TxtID.SetFoc us
                      DoCmd.FindRecor d RecID, acAnywhere, True, acSearchAll, True, acCurrent, True

                      'error handling here
                      End Sub


                      This seems to do exactly what I want regardless of where I am in the
                      records. Any dramas using this?

                      From one hack programmer, thanks everyone for your help! :-)


                      Comment

                      • Bob Quintal

                        #12
                        Re: Requery, Return to record

                        "MS" <Email@Myemail. com> wrote in
                        news:3wLVd.1827 51$K7.103932@ne ws-server.bigpond. net.au:
                        [color=blue]
                        >
                        > "Neil" <njones@pxdy.co m> wrote in message
                        > news:aQCVd.37$c N6.23@newsread1 .news.pas.earth link.net...[color=green]
                        >> In what way are you "navigating " to the next record? This
                        >> code ends when it returns you to the original record. You
                        >> must be navigating through some other means. If it's with the
                        >> navigation buttons at the bottom of the form, then you should
                        >> go to the "new" record. If you're using a custom navigation
                        >> button, then the problem is probably there, and you should
                        >> post the code used there. But this code ends when it takes
                        >> you back to the original record, and, from what I understand,
                        >> that part's working fine.[/color]
                        >
                        >
                        > Thanks.
                        >
                        > I have several custom nav buttons.
                        >
                        > I think the "problem" may be with the way my "requery" code
                        > "bookmarks" .
                        >
                        > Two of the most pertinent buttons are thus.......
                        >
                        >
                        > Private Sub CmdNxtRec_Click ()
                        > On Error GoTo Err_CmdNxtRec_C lick[/color]

                        what a lot of convoluted code to do the same thing as

                        If Me.Recordset.Ab solutePosition + 1 _
                        < Me.Recordset.Re cordCount Then
                        DoCmd.GoToRecor d , , acNext
                        End If


                        --
                        Bob Quintal

                        PA is y I've altered my email address.

                        Comment

                        • Neil

                          #13
                          Re: Requery, Return to record

                          I've always just assumed that requeries go to the beginning, so I've never
                          done a .MoveFirst after a requery, and I've never had any problems. But
                          there's always a first time I suppose.... ;-)

                          N

                          "Tim Marshall" <TIMMY!@PurpleP andaChasers.Moe rtherium> wrote in message
                          news:d07bp8$ibn $1@coranto.ucs. mun.ca...[color=blue]
                          > Neil wrote:
                          >[color=green]
                          >> You don't want to close recordsetclone. Since you don't open
                          >> recordsetclone, you don't need to close it.[/color]
                          >
                          > Exactly.
                          >
                          > Also, if you have any other code that uses recordsetclone without a
                          > requery, keep in mind that the bookmark for recordsetclone stays where you
                          > last left off in .findfirst. If on the next time you use recordsetclone
                          > to search for something, if the next record is BEFORE the last, the
                          > findfirst starts where it last left off and goes to eof and you won't find
                          > it.
                          >
                          > For any use of a recordsetclone, it might be good practice to add in a
                          > .movefirst at ythe end of your procedure, just in case.
                          >
                          > In MS's case, since s/he is requerying before using recordsetclone, the
                          > recordsetclone is reconstructed and starts at the beginning anyway. But,
                          > IMO, it's still good practice to "reset" and .movefirst. I find rsclones
                          > to be very useful sometimes.
                          > --
                          > Tim http://www.ucs.mun.ca/~tmarshal/
                          > ^o<
                          > /#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
                          > /^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me[/color]


                          Comment

                          • Neil

                            #14
                            Re: Requery, Return to record

                            > Private Sub CmdNxtRec_Click ()[color=blue]
                            > On Error GoTo Err_CmdNxtRec_C lick
                            >
                            >
                            > DoCmd.GoToRecor d , , acNext
                            > Dim IntNewrec As Integer
                            >
                            > IntNewrec = Me.NewRecord
                            > If IntNewrec = True Then
                            > MsgBox "End of Data File. " _
                            > & "Returning to last record. " _
                            > & "To create new record, click ""New Record"" "
                            > DoCmd.GoToRecor d , , acFirst
                            >
                            > Dim rst As Recordset
                            > Set rst = CurrentDb.OpenR ecordset("QryPa tientInfo", dbOpenDynaset)
                            > rst.Requery
                            > rst.MoveLast
                            > rst.Delete
                            > rst.Requery
                            > rst.Close
                            > Me.Requery
                            > DoCmd.GoToRecor d , , acLast
                            > End If[/color]

                            Some notes on the above:

                            1) You don't need the rst recordset. You can do everything in the
                            recordsetclone.

                            2) You don't need to requery after performing an OpenRecordset. By opening
                            the recordset, you are "querying" the database for the records. You don't
                            need to "requery" immediately after querying.

                            3) You don't need to requery after deleting the record if you're done with
                            the recordset. The record is deleted with the Delete command. Requerying
                            just gives you a fresh set of records, which you don't need at this point.

                            4) All that being said, I don't see why you're deleting the last record. But
                            perhaps that's another story.......
                            [color=blue]
                            >
                            > BTW, I experimented with this to requery, and return to the record I
                            > "requeried" from ..........
                            >
                            > Private Sub Private Sub CmdRefsh()
                            > 'on error here
                            > Dim RecID As String
                            >
                            > RecID = Me.TxtID
                            > Me.Requery
                            > Me.TxtID.SetFoc us
                            > DoCmd.FindRecor d RecID, acAnywhere, True, acSearchAll, True, acCurrent,
                            > True
                            >
                            > 'error handling here
                            > End Sub
                            >
                            >
                            > This seems to do exactly what I want regardless of where I am in the
                            > records. Any dramas using this?
                            >
                            > From one hack programmer, thanks everyone for your help! :-)[/color]

                            That would work OK. But you should use the RecordsetClone code you were
                            previously given. It's cleaner and doesn't rely on form controls. My
                            understanding is that that works fine, but that you're having problems with
                            the MoveNext button, which is a separate thing.

                            Regarding the MoveNext code, you should set your code to break on all errors
                            (in code window, go to Options, General tab, Break on All Errors), and see
                            the line of code that's giving you an error. That should give you some clue.

                            Neil


                            Comment

                            • MS

                              #15
                              Re: Requery, Return to record


                              "Neil" <njones@pxdy.co m> wrote in message
                              news:2ZdWd.1797 $cN6.67@newsrea d1.news.pas.ear thlink.net...[color=blue][color=green]
                              >> Private Sub CmdNxtRec_Click ()
                              >> On Error GoTo Err_CmdNxtRec_C lick
                              >>
                              >>
                              >> DoCmd.GoToRecor d , , acNext
                              >> Dim IntNewrec As Integer
                              >>
                              >> IntNewrec = Me.NewRecord
                              >> If IntNewrec = True Then
                              >> MsgBox "End of Data File. " _
                              >> & "Returning to last record. " _
                              >> & "To create new record, click ""New Record"" "
                              >> DoCmd.GoToRecor d , , acFirst
                              >>
                              >> Dim rst As Recordset
                              >> Set rst = CurrentDb.OpenR ecordset("QryPa tientInfo", dbOpenDynaset)
                              >> rst.Requery
                              >> rst.MoveLast
                              >> rst.Delete
                              >> rst.Requery
                              >> rst.Close
                              >> Me.Requery
                              >> DoCmd.GoToRecor d , , acLast
                              >> End If[/color]
                              >
                              > Some notes on the above:
                              >
                              > 1) You don't need the rst recordset. You can do everything in the
                              > recordsetclone.
                              >
                              > 2) You don't need to requery after performing an OpenRecordset. By opening
                              > the recordset, you are "querying" the database for the records. You don't
                              > need to "requery" immediately after querying.
                              >
                              > 3) You don't need to requery after deleting the record if you're done with
                              > the recordset. The record is deleted with the Delete command. Requerying
                              > just gives you a fresh set of records, which you don't need at this point.
                              >
                              > 4) All that being said, I don't see why you're deleting the last record.
                              > But perhaps that's another story.......
                              >[color=green]
                              >>
                              >> BTW, I experimented with this to requery, and return to the record I
                              >> "requeried" from ..........
                              >>
                              >> Private Sub Private Sub CmdRefsh()
                              >> 'on error here
                              >> Dim RecID As String
                              >>
                              >> RecID = Me.TxtID
                              >> Me.Requery
                              >> Me.TxtID.SetFoc us
                              >> DoCmd.FindRecor d RecID, acAnywhere, True, acSearchAll, True, acCurrent,
                              >> True
                              >>
                              >> 'error handling here
                              >> End Sub
                              >>
                              >>
                              >> This seems to do exactly what I want regardless of where I am in the
                              >> records. Any dramas using this?
                              >>
                              >> From one hack programmer, thanks everyone for your help! :-)[/color]
                              >
                              > That would work OK. But you should use the RecordsetClone code you were
                              > previously given. It's cleaner and doesn't rely on form controls. My
                              > understanding is that that works fine, but that you're having problems
                              > with the MoveNext button, which is a separate thing.
                              >
                              > Regarding the MoveNext code, you should set your code to break on all
                              > errors (in code window, go to Options, General tab, Break on All Errors),
                              > and see the line of code that's giving you an error. That should give you
                              > some clue.
                              >[/color]


                              Thanks Neil.

                              I'll give that a go to see where the problem is.

                              The reason I delete the record, is that the way this button works if you are
                              on the last record, pushing it one more time creates a new record. Hence the
                              Me.NeRecord check. If True, the record is deleted.

                              Maybe there is a better way?

                              Cheers!


                              Comment

                              Working...