How to navigate on unbounded forms ???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vikas1111
    New Member
    • Feb 2008
    • 122

    #1

    How to navigate on unbounded forms ???

    Hi All
    I want to know how to navigate in unbounded form ??? Can anyone give me an idea ??
  • vikas1111
    New Member
    • Feb 2008
    • 122

    #2
    I am using these codes but i am not able to navigate the records...What should i do?

    [code=vb]
    Private Sub cmdfirst_Click( Index As Integer)
    rsnew3.Open "select * from _____", c, adOpenDynamic
    rsnew3.MoveFirs t
    If rsnew3.State = adstaticopen Then rsnew3.Close
    Set rsnew3 = Nothing
    End Sub

    Private Sub cmdlast_Click(I ndex As Integer)
    rsnew3.Open "select * from ______", c, adOpenDynamic
    rsnew3.MoveLast
    If rsnew3.State = adstaticopen Then rsnew3.Close
    Set rsnew3 = Nothing
    End Sub

    Private Sub cmdnext_Click(I ndex As Integer)
    rsnew3.Open "select * from _______", c, adOpenDynamic
    If Not rsnew3.EOF Then rsnew3.MoveNext
    rsnew3.MoveLast
    If rsnew3.State = adstaticopen Then rsnew3.Close
    Set rsnew3 = Nothing
    End Sub

    Private Sub cmdprev_Click(I ndex As Integer)
    rsnew3.Open "select * from ______", c, adOpenDynamic
    If Not rsnew3.BOF Then rsnew3.MovePrev ious
    rsnew3.MoveFirs t
    If rsnew3.State = adstaticopen Then rsnew3.Close
    Set rsnew3 = Nothing
    End Sub

    Private Sub Form_Load()
    Dim cs As String
    c.Open ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=________ .mdb;Persist Security Info=false")
    RSNew2.Open "select * from ______", c, adOpenDynamic

    Me.Text1.Text = RSNew2(2)
    Me.Text2.Text = RSNew2(3)
    If RSNew2.State = adstaticopen Then RSNew2.Close
    Set RSNew2 = Nothing

    End Sub
    [/code]
    I am not getting any error also...
    can anybody pls help????
    Last edited by debasisdas; Mar 5 '08, 08:29 AM. Reason: added code=vb tags

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      You have opened Rsnew2 and accesing Rsnew3

      and why u have closed the recordset in form load itself.

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        You need not open so many recordsets in Navigation buttons..
        Declare a Recordset Form Level.. And Move and display results..
        Some thing like this :


        [code=vb]
        Option explicit
        Dim RST As New ADODB.Recordset

        Private Sub cmdfirst_Click( Index As Integer)
        RST.MoveFirst
        Call ShowRecs
        End Sub

        Private Sub cmdlast_Click(I ndex As Integer)
        RST.MoveLast
        Call ShowRecs
        End Sub

        Private Sub cmdnext_Click(I ndex As Integer)
        RST.MoveNext
        If RST.BOF Then
        RST.MoveLast
        End If
        Call ShowRecs
        End Sub

        Private Sub cmdprev_Click(I ndex As Integer)
        RST.MovePreviou s
        If RST.BOF Then
        RST.MoveFirst
        End If
        Call ShowRecs
        End Sub

        Private Sub Form_Load()
        Dim cs As String
        c.Open ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=________ .mdb;Persist Security Info=false")
        Set RST= Nothing
        RST.Open "select * from ______", c, adOpenDynamic
        If Not RST.EOF Then
        Call ShowRecs
        End If
        End Sub

        Private Sub ShowRecs()
        Me.Text1.Text = RST(2)
        Me.Text2.Text = RST(3)
        End Sub

        [/code]


        Some Fine tuning is required, but gives you the Basic Idea..

        REgards
        Veena

        Comment

        • vikas1111
          New Member
          • Feb 2008
          • 122

          #5
          Originally posted by debasisdas
          You have opened Rsnew2 and accesing Rsnew3

          and why u have closed the recordset in form load itself.

          Hi ..
          I changed the record set from rsnew3 to rsnew2.. And removed the line which closed the record set in lode itself .. But now i am getting error ..
          The error is:::
          RUN TIME ERROR::3705
          OPERATION IS NOT ALLOWED WHEN OBJECT IS OPEN...IN
          Private Sub cmdprev_Click(I ndex As Integer)

          Comment

          • vikas1111
            New Member
            • Feb 2008
            • 122

            #6
            Hey thanks it worked perfectly...
            Cheers......... .......

            Comment

            • vikas1111
              New Member
              • Feb 2008
              • 122

              #7
              [QUOTE=QVeen72]Hi,




              Hi
              I implemented the same code in my other program.. But there i am getting an error .. Error is ::: Compile error::
              Procedure declaration does not match description of event or procedure having the same name...
              What does it mean and what should i do ????

              Comment

              • QVeen72
                Recognized Expert Top Contributor
                • Oct 2006
                • 1445

                #8
                Hi,

                In this for, your Navigation buttons have got "Index" (Control array)
                and in other forms, they may not have Index...
                In New form, Remove the entire code of navigation buttons
                Copy code from Each button, and double click the button and paste in new form..


                Regards
                Veena

                Comment

                • vikas1111
                  New Member
                  • Feb 2008
                  • 122

                  #9
                  Hey thanks once again.. No actually index number were not given ,, i just numbered them from 0 to3.. Now its working fine..

                  Comment

                  • vikas1111
                    New Member
                    • Feb 2008
                    • 122

                    #10
                    Hi All..
                    Now i am trying to implement navigation by using control array.. Here is my code ..

                    [code=vb]
                    Option Explicit
                    Dim c As New ADODB.Connectio n
                    Dim cm As ADODB.Command
                    Dim rs1 As New ADODB.Recordset

                    Private Sub cmdnav_Click(In dex As Integer)
                    Select Case Index
                    Case 0
                    rs1.movefirst
                    Call ShowRecs
                    Case 1
                    rs1.movepreviou s
                    Call ShowRecs
                    Case 2
                    rs1.movenext
                    Call ShowRecs
                    Case 3
                    rs1.movelast
                    Call ShowRecs
                    End Select
                    End Sub

                    Private Sub Form_Load()
                    Dim cs As String
                    Dim RSNew As New ADODB.Recordset
                    Dim RSNew1 As New ADODB.Recordset
                    c.Open ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=______.m db;Persist Security Info=false")
                    End Sub

                    Private Sub ShowRecs()
                    rs1.Open "select * from _______", c, adOpenDynamic
                    Me.Text1.Text = rs1(3)
                    End Sub

                    Private Sub setnavigationbu tton(bval As Boolean)
                    Dim i As Integer
                    For i = 0 To 3
                    cmdnav(i).Enabl ed = bval
                    Next
                    End Sub
                    [/code]
                    error i am getting is

                    ERROR 3704 ,,,, OPERATION IS NOT ALLOWED WHWN OBJECT IS CLOSED...
                    Private Sub ShowRecs()

                    rs1.Open "select * from setting", c, adOpenDynamic<-------HERE
                    Last edited by debasisdas; Mar 7 '08, 06:33 AM. Reason: added code=vb tags

                    Comment

                    • QVeen72
                      Recognized Expert Top Contributor
                      • Oct 2006
                      • 1445

                      #11
                      Hi,

                      Before Opening a Recordset set it to nothing..:

                      [code=vb]
                      Private Sub ShowRecs()
                      Set rs1 = Nothing
                      rs1.Open "select * from setting", c, adOpenDynamic
                      End Sub
                      [/code]

                      This is a Quick and Dirty Solution.... but works

                      The Error is Because, you have a Recordset rs1 in the project, where you have opened and not Closed.. It's always good practice to close the recset after use.. (Or else close it in FormUnload event)

                      Regards
                      Veena

                      Comment

                      • vikas1111
                        New Member
                        • Feb 2008
                        • 122

                        #12
                        Originally posted by QVeen72
                        Hi,

                        Before Opening a Recordset set it to nothing..:

                        [code=vb]
                        Private Sub ShowRecs()
                        Set rs1 = Nothing
                        rs1.Open "select * from setting", c, adOpenDynamic
                        End Sub
                        [/code]

                        This is a Quick and Dirty Solution.... but works

                        The Error is Because, you have a Recordset rs1 in the project, where you have opened and not Closed.. It's always good practice to close the recset after use.. (Or else close it in FormUnload event)

                        Regards
                        Veena

                        Hi i tried it.. Now i am not getting any error but the navigation buttons are not responding.. I guess i have gone wrong in coding the control array..Can you just check out and tell me where i have gone wrong ??

                        Comment

                        • QVeen72
                          Recognized Expert Top Contributor
                          • Oct 2006
                          • 1445

                          #13
                          Hi,

                          Write the codes Neatly.. You have created a mess.. Dont Unnecessarily open recset and use so many Variables..
                          INDENT Properly..
                          Any way try this :

                          [code=vb]
                          Option Explicit
                          Dim c As New ADODB.Connectio n
                          Dim cm As ADODB.Command
                          Dim rs1 As New ADODB.Recordset

                          Private Sub cmdnav_Click(In dex As Integer)
                          Select Case Index
                          Case 0
                          rs1.movefirst
                          Call ShowRecs
                          Case 1
                          rs1.movepreviou s
                          Call ShowRecs
                          Case 2
                          rs1.movenext
                          Call ShowRecs
                          Case 3
                          rs1.movelast
                          Call ShowRecs
                          End Select
                          End Sub

                          Private Sub Form_Load()
                          c.Open ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=______.m db;Persist Security Info=false")
                          Set rs1 =Nothing
                          rs1.Open "select * from _______", c, adOpenDynamic
                          If Not rs1.EOF Then
                          rs1.MoveFirst
                          Call ShowRecs
                          Call setnavigationbu tton(True)
                          Else
                          Call setnavigationbu tton(False)
                          End If
                          End Sub

                          Private Sub ShowRecs()
                          Me.Text1.Text = rs1(3)
                          End Sub

                          Private Sub setnavigationbu tton(bval As Boolean)
                          Dim i As Integer
                          For i = 0 To 3
                          cmdnav(i).Enabl ed = bval
                          Next
                          End Sub
                          [/code]

                          REgards
                          Veena

                          Comment

                          • vikas1111
                            New Member
                            • Feb 2008
                            • 122

                            #14
                            Originally posted by QVeen72
                            Hi,

                            Write the codes Neatly.. You have created a mess.. Dont Unnecessarily open recset and use so many Variables..
                            INDENT Properly..
                            I am new to vb .. fine i will implement what all you have mentioned above.......... ......

                            Comment

                            Working...