Next Record Button. Combo box. Code sub not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jambonjamasb
    New Member
    • Jan 2008
    • 41

    Next Record Button. Combo box. Code sub not working

    Hi All,

    I am now on the next part of my quest.

    I have built my Form, which has used subforms to show my records and what I need to complete as the POL authority.

    I am now trying to jazz the form up so I thought of adding a next record and previous record button.

    I added two combo boxes called Next_Record and Previous_Button .

    I selected code builder and added the following scripts.

    Private Sub Next_Record_Cli ck()

    Me.POL_Ref.SetF ocus

    If (Me.POL_Ref.Lis tIndex = Me.POL_Ref.List Count - 1) Then

    Else
    Me.POL_Ref.List Index = (Me.POL_Ref.Lis tIndex + 1)
    End If

    End Sub

    Private Sub Previous_Button _Click()
    Me.POL_Ref.SetF ocus

    If (Me.POL_Ref.Lis tIndex = 0) Then

    Else
    Me.POL_Ref.List Index = (Me.POL_Ref.Lis tIndex - 1)
    End If
    End Sub

    I go onto the my report screen and press the buttons and nothing happens no error or anything.

    I have tried to use the unique number in the POL_Ref field of my form?

    I can't see the wood for the trees now.
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    You have, indeed, over complicated things! I think the first thing you need to do is to delete everything you have so far; buttons, comboboxes and code. To do otherwise is only going to confuse things. Place two buttons on your form, naming them Go2Next and Go2Previous. Then place this code behind the appropriate button:

    [CODE=vb]Private Sub Go2Next_Click()
    On Error GoTo Err_Go2Next_Cli ck

    DoCmd.GoToRecor d , , acNext

    Exit_Go2Next_Cl ick:

    Exit Sub

    Err_Go2Next_Cli ck:

    If Err.Number = 2105 Then
    MsgBox "This is the Last Record"
    Else
    MsgBox Err.Description
    Resume Exit_Go2Next_Cl ick
    End If

    End Sub[/CODE]

    [CODE=vb] Private Sub Go2Previous_Cli ck()
    On Error GoTo Err_Go2Previous _Click

    DoCmd.GoToRecor d , , acPrevious

    Exit_Go2Previou s_Click:

    Exit Sub

    Err_Go2Previous _Click:

    If Err.Number = 2105 Then
    MsgBox "This is the First Record"
    Else
    MsgBox Err.Description
    Resume Exit_Go2Previou s_Click
    End If

    End Sub[/CODE]

    If the user is at the first record and tries to go to the previous record, a message box will pop up explaining this. If at the last record and the user tries to go to the next record, this, too, will be explained.

    Linq ;0)>

    Comment

    • jambonjamasb
      New Member
      • Jan 2008
      • 41

      #3
      LOL thank you so much. I will try this in the morning as I am too tired to see the screen now.

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        Good call! After 15 years I can tell you, it's almost always counter- productive to attempt programming when you're tired!

        Linq ;0)>

        Comment

        • jambonjamasb
          New Member
          • Jan 2008
          • 41

          #5
          Thanks Miss Ingling,

          I did the following at it seems to work.

          Private Sub Command23_Click ()
          On Error GoTo Err_Command23_C lick


          DoCmd.GoToRecor d , , acNext

          Exit_Command23_ Click:
          Exit Sub

          Err_Command23_C lick:
          MsgBox Err.Description
          Resume Exit_Command23_ Click

          End Sub
          Private Sub Command24_Click ()
          On Error GoTo Err_Command24_C lick


          DoCmd.GoToRecor d , , acPrevious

          Exit_Command24_ Click:
          Exit Sub

          Err_Command24_C lick:
          MsgBox Err.Description
          Resume Exit_Command24_ Click

          End Sub

          LOL Which is basically what you said. Thanks again you are a star.

          Comment

          • missinglinq
            Recognized Expert Specialist
            • Nov 2006
            • 3533

            #6
            Glad you got it figured out! Be aware, though, that if, at the beginning or end of your recordset, the user tries to move again, they will get an error message that says "You can't go to the specified record" without any other explanation! Some users find this confusing!

            Linq ;0)>

            Comment

            • jambonjamasb
              New Member
              • Jan 2008
              • 41

              #7
              Thank you I will try to change it then.

              Comment

              Working...