Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 '---------------------------------- ------------------- -- Brian ----------------------------------------------------------------------- BrianB's Profile: http://www.excelforum.com/member.php...tinfo&userid=5 View this thread: http://www.excelforum.com/showthread.php?threadid=27560 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank you Brian. I'll give this a try.
"BrianB" wrote: You are making the job hard for yourself. You only need to keep track of the current data row. This principle follows for adding new and deleting 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 '---------------------------------- -------------------- -- BrianB ------------------------------------------------------------------------ BrianB's Profile: http://www.excelforum.com/member.php...info&userid=55 View this thread: http://www.excelforum.com/showthread...hreadid=275601 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Move to next record | Excel Discussion (Misc queries) | |||
User Record | Excel Worksheet Functions | |||
How do I fill a cell in a user form from a selection on same form? | Excel Discussion (Misc queries) | |||
I am looking to see if anybody has an equivalant user form to Outlooks CONTACT form | Excel Programming |