Next / Previous Button Code

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,271
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I have a database & userform im making but now stuck again.
On my userform i can click a button and the first record is imported from the database into the form.
I would now like to browse my other files hence record 3,4,5 etc with the use of Next / Previous buttons.
Can you advise a code for the Next / Previous files.

Thanks
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Please explain your definition of "File" and "Record"

I think of "Record" as a "Row"
I think of "File" as a "Workbook"

You use both words in your question.

You may need to rewrite your question.

And show us your Userform button script
 
Last edited:
Upvote 0
I'm rubbish at explaining things.

I have a database & user form im making but now stuck again.
On my userform i can click a button and the customer & info related to him is imported from the database into the form.

Now whilst still in the user form I would like to click the next button so the next customer along with his related info is now imported into the user form which obviously replaces the previous customer.

But by then clicking the back button I can go back to him.

Basically as opposed to going through each customer in the database I want to do it in the user form.

I will switch PC in and show my code.
 
Upvote 0
Below is the code i use to import the data from the first customer in my database into the user form.
I would like please some code that i can add to the NEXt & Previous button so i can then look at the next customer along with his details then the next etc etc.
And by clicking the Previous button be able to go backwards.

Code:
Private Sub cmdGet_Click()
txtCustomer.Text = Range("A6").Value
txtRegistrationNumber.Text = Range("B6").Value
txtBlankUsed.Text = Range("C6").Value
txtVehicle.Text = Range("D6").Value
txtButtons.Text = Range("E6").Value
txtKeySupplied.Text = Range("F6").Value
txtTransponderChip.Text = Range("G6").Value
txtJobAction.Text = Range("H6").Value
txtProgrammerCloner.Text = Range("I6").Value
txtKeyCode.Text = Range("J6").Value
txtBiting.Text = Range("K6").Value
txtChassisNumber.Text = Range("L6").Value
txtJobDate.Text = Range("M6").Value
txtVehicleYear.Text = Range("N6").Value
txtPaid.Text = Range("O6").Value
End Sub
 
Upvote 0
I'm assuming
txtProgrammerCloner.Text

Is a textbox on your userform

If all your wanting to do is look at your data.
I would suggest another approach.

Create yourself a Listbox

Make your listbox as wide as your Userform the listbox can be very narrow in height.
Make yourself a Textbox Named Textbox1

Then you will need a previous and next button

This way all your rows data from column A to column N will showup in the one Listbox
When you press the next and previous buttons it will now show you the data in the next or previous row.

Try using my code below:
Let me know what you think of this approach or if you need more help


Code:
Private Sub CommandButton2_Click()
'Next Button code
Dim one As Long
Dim Start As Long
one = TextBox1.Value + 1
ListBox1.RowSource = "A" & one & ":N" & one
TextBox1.Value = one
End Sub

Private Sub CommandButton3_Click()
'Previous Button Code
Dim one As Long
one = TextBox1.Value - 1
If TextBox1.Value = 1 Then Exit Sub
ListBox1.RowSource = "A" & one & ":N" & one
TextBox1.Value = one
End Sub

Private Sub UserForm_Initialize()
ListBox1.ColumnCount = 14
ListBox1.RowSource = "A6:N6"
TextBox1.Value = "6"
End Sub
 
Last edited:
Upvote 0
Hi
Thanks for that.
I will try it tomorrow.
For now I think the with of my user form is as wide as I could have it, I could be wrong but will need to check.

I would like this text box the to sit about my first text box but that is close to the top border of the user form.

Without manually moving all the boxes again etc how can I put some space where I need to put it so the boxes drop down enough for me to put this new box.
 
Upvote 0
Hi,

Ive done what you advise.
I see the first customer but next / previous has no affect.
Also the text box just shows a 6 in it ?

Is there a way to also show the labels above the details as some show n/a but i need to what it refers to.
This is whay i was thinking of just importing into the text boxes already in place.
 
Last edited:
Upvote 0
Ha Ha.
Rename buttons,now working

Im just looking at it and will reply soon.

Thanks
 
Upvote 0
Yes I'm just showing you a way to do this with just one listbox. and one textbox
Instead of labels above each column I have another plan where we could have the header column always showing.
The reason why 6 first shows up in textbox is because you said you wanted to start with row 6.
I'll get back with you on a way to always show the header row I believe I can do that
 
Upvote 0
Ok
As you replied i am typing a new post.
Yes that is correct with row 6 but i can at present press previous and go back to 5,4,3,2,1 can we code it so 6 is the limit etc.
I will put the reply here when finished and see what you think.

I will pick this up again tomorrow,many thanks for your time on this.
 
Upvote 0

Forum statistics

Threads
1,215,972
Messages
6,128,030
Members
449,414
Latest member
sameri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top