PDA

View Full Version : cmdButton for Next & Previous records



matty25
11-03-2008, 12:41 PM
I wonder if someone could help me please.

I need some vba code for use on an Excel userform to scroll through previous and next records by use of cmdPrev and cmdNext buttons respectively.

Thanks, Matt

Bob Phillips
11-03-2008, 02:52 PM
You would need to give us the workbook that you have now, with the data, the form, and any code you have, otherwsie the brief is far to generic.

grandflavour
11-03-2008, 09:56 PM
Isnt this the same as your other thread?

Anyway as stated its too generic. Where is the data from? From the excel spreadsheet? If so then just have a simple counter and the userform uses that counter in the reference of cells where:


private sub btnNext_click()

counter = counter + 1
textbox1 = cells(counter, 1)

end sub

matty25
11-04-2008, 11:33 AM
Isnt this the same as your other thread?

Anyway as stated its too generic. Where is the data from? From the excel spreadsheet? If so then just have a simple counter and the userform uses that counter in the reference of cells where:


private sub btnNext_click()

counter = counter + 1
textbox1 = cells(counter, 1)

end sub

Thanks for the reply grand, sorry, I haven't given enough information. The data is coming from an excel spreadsheet into frmRecord2, and is to be presented on this form, the < & > buttons will scroll previous and next results respectively. The data on the spreadsheet is a supplier database with name, address, tel bumber, fax number etc across the top (columns) and the database is filled downwards.

Here is an image of the form used to recall information from the spreadsheet, but to be honest i havent figured out a code yet to call the information to the textboxes but this should be fairly simple (fingers crossed). The < > cmdbuttons will then effectively scroll down the page going through each record one at a time.

http://d.imagehost.org/0110/Untitled_2.jpg

Hope this helps, sorry for being vague. P.s. the copy button copies the information from the textboxes to the clipboard for use in other programs eg word. I already have the code to copy the data in the textboxes to the clipboard.

Cheers, Matt

Demosthine
11-06-2008, 01:08 PM
Good Afternoon.

Excel does not have anything like a MoveNext or MovePrevious like Access does, so you have to do this manually.

You'll want to either add a Label to the Form, set it to Invisible, and store the current Row Number on it...
OR
Add a Module Level Variable of type Integer to store the Row Number.

Essentially, you are storing the current Record's Row Number. Then you can cycle through your data by incrementing and decrementing that Variable. Access the specific data using:


Worksheets("AddressData").Cells(intRow, 1).Value = txtName.Text


Good luck.
Scott