473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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_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
6 4795
missinglinq
3,532 Expert 2GB
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
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
3,532 Expert 2GB
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
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
3,532 Expert 2GB
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
Thank you I will try to change it then.
Jan 10 '08 #7

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

Similar topics

7
by: Megan | last post by:
Hi everybody- I inherited a database that somehow uses a bound combo box as a record selector. Let me give you some background. The form is based on data from 2 tables. The first table, Person,...
6
by: AA Arens | last post by:
Hi, I have a database with 2 main forms. Contacts and companies. I share the base with two others via LAN. On the companies form I have buttons to navigate throught the records (>400). We are...
7
by: gjoneshtfc | last post by:
Hello I want to search my database for a vehicle registration number but before i can search using the Find Record button i created i have to click in the registration field so that it is that...
1
by: foothills bhc | last post by:
I have a problem with verifying content of controls on a form before closing the form or moving to the next form "record" (i.e., when moving to the next row of my form's record source). HERE'S THE...
3
by: mf193 | last post by:
Hi, I have a table of around 1000 rows; patient records. Each row is individually defined by a Patient ID number which is my primary key. I have made a simple form to display patient information...
6
by: AppDev63 | last post by:
I've been struggling with a form. On the left side of the form I've got data from a table of invoices, and on the right side I've got a combo box with data from a table of payments. The user scrolls...
6
by: banderson | last post by:
Hello, I have a form and a combo box that I use to filter the form to particular records. I also have an "add new" button that, when clicked, adds a new record. My problem is that the filter combo...
1
by: Coll | last post by:
I'm working on a database that someone else created. I have a form - frm_main that is based on a query that is based on two tables. The join is such that the first table tbl_JCN has all records...
0
by: solargovind | last post by:
Hello, I have few problem with Dlookup condition. I need to retrieve next record or previous record based on certain condition. The conditions are set in in the combo box. Here, I am trying to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.