By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,557 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

Next Record Button. Combo box. Code sub not working

P: 41
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_Click()

Me.POL_Ref.SetFocus

If (Me.POL_Ref.ListIndex = Me.POL_Ref.ListCount - 1) Then

Else
Me.POL_Ref.ListIndex = (Me.POL_Ref.ListIndex + 1)
End If

End Sub

Private Sub Previous_Button_Click()
Me.POL_Ref.SetFocus

If (Me.POL_Ref.ListIndex = 0) Then

Else
Me.POL_Ref.ListIndex = (Me.POL_Ref.ListIndex - 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.
Jan 10 '08 #1
Share this Question
Share on Google+
6 Replies


missinglinq
Expert 2.5K+
P: 3,532
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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Go2Next_Click()
  2.  On Error GoTo Err_Go2Next_Click
  3.  
  4.     DoCmd.GoToRecord , , acNext
  5.  
  6. Exit_Go2Next_Click:
  7.  
  8.    Exit Sub
  9.  
  10.  Err_Go2Next_Click:
  11.  
  12.  If Err.Number = 2105 Then
  13.    MsgBox "This is the Last Record"
  14.  Else
  15.    MsgBox Err.Description
  16.    Resume Exit_Go2Next_Click
  17.  End If
  18.  
  19. End Sub
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Go2Previous_Click()
  2. On Error GoTo Err_Go2Previous_Click
  3.  
  4. DoCmd.GoToRecord , , acPrevious
  5.  
  6. Exit_Go2Previous_Click:
  7.  
  8.     Exit Sub
  9.  
  10. Err_Go2Previous_Click:
  11.  
  12. If Err.Number = 2105 Then
  13.     MsgBox "This is the First Record"
  14. Else
  15.     MsgBox Err.Description
  16.     Resume Exit_Go2Previous_Click
  17. End If
  18.  
  19. End Sub
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)>
Jan 10 '08 #2

P: 41
LOL thank you so much. I will try this in the morning as I am too tired to see the screen now.
Jan 10 '08 #3

missinglinq
Expert 2.5K+
P: 3,532
Good call! After 15 years I can tell you, it's almost always counter- productive to attempt programming when you're tired!

Linq ;0)>
Jan 10 '08 #4

P: 41
Thanks Miss Ingling,

I did the following at it seems to work.

Private Sub Command23_Click()
On Error GoTo Err_Command23_Click


DoCmd.GoToRecord , , acNext

Exit_Command23_Click:
Exit Sub

Err_Command23_Click:
MsgBox Err.Description
Resume Exit_Command23_Click

End Sub
Private Sub Command24_Click()
On Error GoTo Err_Command24_Click


DoCmd.GoToRecord , , acPrevious

Exit_Command24_Click:
Exit Sub

Err_Command24_Click:
MsgBox Err.Description
Resume Exit_Command24_Click

End Sub

LOL Which is basically what you said. Thanks again you are a star.
Jan 10 '08 #5

missinglinq
Expert 2.5K+
P: 3,532
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)>
Jan 10 '08 #6

P: 41
Thank you I will try to change it then.
Jan 10 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.