Move to Next Record with User Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a user form where I need to control record navigation. Upon
activation, the form goes to the first record. I have command buttons on the
form that need to move the user to the "previous" or "next" record and I
can't figure out how to make that work. Please help.

I tried this:

dim firstrow as object
set firstrow=shee1.range("b2").end(xldown)
firstrow.offset(1,0).value=textbox1.text
etc.
then I thought I'd loop through this by adding 1 at the end.

I get an error message "object required"

Thank you.
 
You are making the job hard for yourself. You only need to keep track o
the current data row. This principle follows for adding new and deletin
records. Here is some basic code to go into a userform :-

Code
-------------------

'- general declaration
Dim CurrentRow As Long
'----------------------------------
'-initialise when form opened
Private Sub UserForm_Initialize()
CurrentRow = 1
Update_Form
End Sub
'-----------------------------------
'- next record button
Private Sub CommandButton1_Click()
CurrentRow = CurrentRow + 1
Update_Form
End Sub
'---------------------------------
'- previous record button
Private Sub CommandButton2_Click()
If CurrentRow > 2 Then ' row 1 has headings
Set CurrentRow = CurrentRow - 1
Update_Form
Else
MsgBox ("Top of table")
End If
End Sub
'--------------------------------
'- common use subroutine
Sub Update_Form()
TextBox1.Value = Worksheets("Data").Cells(CurrentRow, 1).Value
TextBox2.Value = Worksheets("Data").Cells(CurrentRow, 2).Value
End Sub
'----------------------------------

-------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top