Consulting

Results 1 to 5 of 5

Thread: cmdButton for Next & Previous records

  1. #1
    VBAX Regular
    Joined
    Nov 2008
    Posts
    14
    Location

    cmdButton for Next & Previous records

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    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:

    [VBA]
    private sub btnNext_click()

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

    end sub[/VBA]

  4. #4
    VBAX Regular
    Joined
    Nov 2008
    Posts
    14
    Location
    Quote Originally Posted by grandflavour
    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:

    [vba]
    private sub btnNext_click()

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

    end sub[/vba]
    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.



    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

  5. #5
    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:

    [VBA]
    Worksheets("AddressData").Cells(intRow, 1).Value = txtName.Text
    [/VBA]

    Good luck.
    Scott
    You don't understand anything until you learn it more than one way. ~Marvin Minsky

    I never teach my pupils; I only attempt to provide the conditions in which they can learn. - Albert Einstein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •