Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 175
Default Should I use Do-While loop for my record counter?

This macro will find a record via user input, then UserForm13 opens up,
showing the record. I recently added code to the sub attempting a Do
While loop. I've never written any of the Do loops before. I'm
doing this in an attempt to assign a number to each record found. I
want this so I can show that number in the userform in TextBox16, to
go with the number I already have there, which shows the total number
of records found.
(The code I have for TextBox16 in UserForm13 is below the sub code.) As
the Next button is clicked in the userform, the next record comes up. I
want TextBox16 to show that number assigned to it.

Obviously I don't have it quite right. There is no error when I run
this. However, the number in TextBox16 stays at 1 no matter which of
the found records I click to. For each record I click to, it should
show 2, 3, 4, etc.

I've thought that maybe I'm using the wrong statement. Maybe I
should be using
For-Each instead of Do-While.

Can someone please point me in the right direction?
Thanks,
J.O.


Sub TestFind_POCurrent()
Worksheets("Official List").Activate
RecordsFound = 0

'*****This is the initial search based on user input.
Set rngToSearch = Sheets("Official List").Columns("J")
Set rngFound = rngToSearch.Find(What:=FindPOVal, _
LookIn:=xlValues, _
LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "This record was not found. Make sure you entered the
correct number. Also, check the Deleted List."
Unload UserForm12 ' UF12 is where user inputs the PO number
UserForm12.Show
Else

strFirst = rngFound.Address
rngFound.Select
RecordsFound = 1
End If

'****my attempt to number each record found
Do While NumberNextRecord = True
Set rngFound = rngToSearch.FindNext(rngFound)
If rngFound Is Nothing Then
NumberNextRecord = False

Else
NumberNextRecord = True
RecordsFound = RecordsFound + 1
End If

Loop

Unload UserForm12
UserForm13.Show
End Sub

*****I thought that the above code would assign a sequential number to
each
record found... RecordsFound = RecordsFound + 1. Obviously its
only entering the number 1 for the term RecordsFound, and not adding 1
for each record.

********
'TextBox16 within UserForm13 shows the number assigned to this record
'This goes with TextBox15, which shows the total records found.

TextBox16.Value = RecordsFound

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
Open new record with selected fields from previous record Design by Sue Excel Discussion (Misc queries) 1 June 12th 09 02:24 PM
Can somebody explain to me how Bob Phillips' unique record counter works? Ken Johnson Excel Programming 4 September 22nd 05 10:59 PM
Record Macro - Record custom user actions Sal[_4_] Excel Programming 1 December 23rd 04 03:18 PM
Counter & Loop tutorial website Jill[_7_] Excel Programming 1 June 25th 04 02:12 AM
On Screen Loop Counter simoncohen Excel Programming 3 April 2nd 04 10:36 AM


All times are GMT +1. The time now is 06:45 PM.

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"