Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Move to Next Record with User Form

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Move to Next Record with User Form


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Move to Next Record with User Form

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Move to next record Wavequation Excel Discussion (Misc queries) 0 October 15th 09 05:22 PM
User Record nabanco Excel Worksheet Functions 5 September 29th 07 12:38 PM
How do I fill a cell in a user form from a selection on same form? Terry Tipsy Excel Discussion (Misc queries) 4 June 11th 07 02:59 PM
I am looking to see if anybody has an equivalant user form to Outlooks CONTACT form BruceJ[_2_] Excel Programming 2 October 15th 03 05:28 PM


All times are GMT +1. The time now is 09:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"