Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default autonumbering in a userform

I have created a userform for entering data into a list.
Each time the form is opened it automatically generates a reference number
and current date using the code listed below:

My problem is that if the userform is closed without entering data to the
list - the number on the form will still increase (next time opened) - also I
want the userform to be available to a number of users over a network so this
type of counter will not work very well.

Idealy I would like the userform on acitvation to search my list for the
largest number and + 1 to give the new number - is this possible what code
should i use?


Private Sub UserForm_initialize()
counter = GetSetting("XYZ Corp", "issuenum", "count", 0)
counter = counter + 1
SaveSetting "XYZ corp", "issuenum", "count", counter
Range("issuenum") = counter
Range("datelogged") = Now

If IsDate(ActiveCell.Value) Then
Calendar1.Value = DateValue(ActiveCell.Value)
Else
Calendar1.Value = Date
End If
End Sub

P.s - The date code I am using gives dates in the format m/d/y I would
prefer dates in the format d/m/year - how can I do this.

Thanks for any help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default autonumbering in a userform

Looks like you are writing the incremented counter to the registry in the
form's intitalise event. Why not do that when the form unloads subject to
checking the incremented value should be written. Put the code in the event
of whatever control closes the form or Queryclose.

Not sure where your list is but maybe something like

vList = Array(4, 2, 7, 4)
maxval = Application.WorksheetFunction.Max(vList)

Debug.Print Format(DateValue(ActiveCell.Value), "d/m/yyyy")

Regards,
Peter T

"Mark Campbell" wrote in message
...
I have created a userform for entering data into a list.
Each time the form is opened it automatically generates a reference number
and current date using the code listed below:

My problem is that if the userform is closed without entering data to the
list - the number on the form will still increase (next time opened) -

also I
want the userform to be available to a number of users over a network so

this
type of counter will not work very well.

Idealy I would like the userform on acitvation to search my list for the
largest number and + 1 to give the new number - is this possible what code
should i use?


Private Sub UserForm_initialize()
counter = GetSetting("XYZ Corp", "issuenum", "count", 0)
counter = counter + 1
SaveSetting "XYZ corp", "issuenum", "count", counter
Range("issuenum") = counter
Range("datelogged") = Now

If IsDate(ActiveCell.Value) Then
Calendar1.Value = DateValue(ActiveCell.Value)
Else
Calendar1.Value = Date
End If
End Sub

P.s - The date code I am using gives dates in the format m/d/y I would
prefer dates in the format d/m/year - how can I do this.

Thanks for any help



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default autonumbering in a userform

Thks Peter - codes worked a treat

"Mark Campbell" wrote:

I have created a userform for entering data into a list.
Each time the form is opened it automatically generates a reference number
and current date using the code listed below:

My problem is that if the userform is closed without entering data to the
list - the number on the form will still increase (next time opened) - also I
want the userform to be available to a number of users over a network so this
type of counter will not work very well.

Idealy I would like the userform on acitvation to search my list for the
largest number and + 1 to give the new number - is this possible what code
should i use?


Private Sub UserForm_initialize()
counter = GetSetting("XYZ Corp", "issuenum", "count", 0)
counter = counter + 1
SaveSetting "XYZ corp", "issuenum", "count", counter
Range("issuenum") = counter
Range("datelogged") = Now

If IsDate(ActiveCell.Value) Then
Calendar1.Value = DateValue(ActiveCell.Value)
Else
Calendar1.Value = Date
End If
End Sub

P.s - The date code I am using gives dates in the format m/d/y I would
prefer dates in the format d/m/year - how can I do this.

Thanks for any help

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
Autonumbering hmk311 Excel Worksheet Functions 5 October 27th 07 01:07 AM
autonumbering Lino Excel Worksheet Functions 2 May 30th 05 02:33 AM
Autonumbering Bernice[_2_] Excel Programming 0 February 11th 04 06:55 PM
Autonumbering Greg Excel Programming 2 February 4th 04 01:34 PM
Autofill - Autonumbering Greg Excel Programming 4 February 3rd 04 05:35 PM


All times are GMT +1. The time now is 10:34 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"