Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Access

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-11-2008, 07:54 PM
=?Utf-8?B?RGFubnkgQmFpcmQ=?=
 
Posts: n/a
AutoNumber Minimum Value

Okay what I really need is an answer in simple step-by-step,
impossible-to-screw-up intructions for the following PROBLEM: Where do I
enter the minimum value for an AutoNumber? It starts at 1 which is obviously
inconvenient for a lot of applications.

I need an automatic numbering system that starts at 10000, it doesn't matter
if a number is skipped because someone deletes a record, just as long as the
numbers are sequential and don't use any numbers before the minimum (10000).

Please be patient with me and explain where I go to do the magic and what
tricks I'll need to perform because I'm very new to this.

Thanks,
--
~ Danny ~
Reply With Quote
  #2 (permalink)  
Old 08-11-2008, 08:07 PM
James A. Fortune
 
Posts: n/a
Re: AutoNumber Minimum Value

Danny Baird wrote:
> Okay what I really need is an answer in simple step-by-step,
> impossible-to-screw-up intructions for the following PROBLEM: Where do I
> enter the minimum value for an AutoNumber? It starts at 1 which is obviously
> inconvenient for a lot of applications.
>
> I need an automatic numbering system that starts at 10000, it doesn't matter
> if a number is skipped because someone deletes a record, just as long as the
> numbers are sequential and don't use any numbers before the minimum (10000).
>
> Please be patient with me and explain where I go to do the magic and what
> tricks I'll need to perform because I'm very new to this.
>
> Thanks,


I think Allen Browne did that here:

http://allenbrowne.com/ser-26.html

James A. Fortune
MPAPoster@FortuneJames.com
Reply With Quote
  #3 (permalink)  
Old 08-11-2008, 08:22 PM
=?Utf-8?B?RGFubnkgQmFpcmQ=?=
 
Posts: n/a
Re: AutoNumber Minimum Value

Very helpful J.A.F., but like I said I need someone to explain the WHERE to me.

I mean that I really know very little about codes like that and that I have
NO idea WHERE to paste that sub.

If someone could puh-leeeeease give me the step-by-step instructions I would
be so thankful.
--
~ Danny ~


"James A. Fortune" wrote:

> Danny Baird wrote:
> > Okay what I really need is an answer in simple step-by-step,
> > impossible-to-screw-up intructions for the following PROBLEM: Where do I
> > enter the minimum value for an AutoNumber? It starts at 1 which is obviously
> > inconvenient for a lot of applications.
> >
> > I need an automatic numbering system that starts at 10000, it doesn't matter
> > if a number is skipped because someone deletes a record, just as long as the
> > numbers are sequential and don't use any numbers before the minimum (10000).
> >
> > Please be patient with me and explain where I go to do the magic and what
> > tricks I'll need to perform because I'm very new to this.
> >
> > Thanks,

>
> I think Allen Browne did that here:
>
> http://allenbrowne.com/ser-26.html
>
> James A. Fortune
> MPAPoster@FortuneJames.com
>

Reply With Quote
  #4 (permalink)  
Old 08-11-2008, 09:16 PM
James A. Fortune
 
Posts: n/a
Re: AutoNumber Minimum Value

Danny Baird wrote:
> Very helpful J.A.F., but like I said I need someone to explain the WHERE to me.
>
> I mean that I really know very little about codes like that and that I have
> NO idea WHERE to paste that sub.
>
> If someone could puh-leeeeease give me the step-by-step instructions I would
> be so thankful.


O.K. First you need to put the word "Public" before the Sub:

Public Sub SetAutoNumber(...

Then copy and paste the subroutine into a new module. Note that the
table needs to have an AutoNumber field such as an AutoNumber Primary
Key called perhaps ID. The code should find it automatically. It might
be a good idea to run the subroutine before the table has any records in
it if you don't want original low numbers kept along with the new ones.

Then you can call the subroutine from, say, the On Click event of a
button on a form:

Public Sub cmdSetAutoNumberStart_Click()
Call SetAutoNumber("MyTable", 10000)
MsgBox("Done.")
End Sub

After that, any new ID values will start at 10000. The code also checks
to see if you already have ID values that are >= 10000 and allows you to
take appropriate action.

(for the lurkers):

In reality the values "MyTable" and 10000 would be from a combobox and a
textbox on the form. If I have a table called tblTables with a text
field called TableName I can fill a combobox with the table names of the
local tables starting with "tbl" in the database as follows:

Private Sub Form_Load()
Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Dim CountRS As DAO.Recordset
Dim tdfLoop As TableDef
Dim lngCount As Long
Dim I As Integer
Dim strSQL As String

'Need to get all the tables for the combo box

Set MyDB = CurrentDb
strSQL = "SELECT * FROM tblTables;"
Set CountRS = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
CountRS.MoveLast
lngCount = CountRS.RecordCount
CountRS.Close
Set CountRS = Nothing
DoEvents

If lngCount > 0 Then
'First delete the rows from tblTables
strSQL = "DELETE tblTables FROM tblTables"
DoCmd.Hourglass True
MyDB.Execute strSQL, dbFailOnError
DoCmd.Hourglass False
'Wait until the records have been deleted
If lngCount > 1 Then
Do While MyDB.RecordsAffected < 1
DoEvents
Loop
End If
End If

'Now refill tblTables
Set MyRS = MyDB.OpenRecordset("tblTables", dbOpenDynaset)
I = 1
For Each tdfLoop In MyDB.TableDefs
I = I + 1
If Left(tdfLoop.Name, 3) = "tbl" Then
MyRS.AddNew
MyRS("TableName") = tdfLoop.Name
MyRS.Update
End If
Next tdfLoop
Set MyDB = Nothing

'Then set the combobox Rowsource to tblTables
cbxTable.RowSource = "SELECT TableName FROM tblTables ORDER BY TableName;"
End Sub

James A. Fortune
MPAPoster@FortuneJames.com
Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Access


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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



All times are GMT. The time now is 07:23 AM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Credit Reports | Loans | Loans | Loans | TurboTax



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114