Google Answers Logo
View Question
 
Q: Autonumber Field in Microsoft Access database ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Autonumber Field in Microsoft Access database
Category: Computers > Programming
Asked by: gravey-ga
List Price: $5.00
Posted: 17 Oct 2002 21:36 PDT
Expires: 16 Nov 2002 20:36 PST
Question ID: 80022
How can I create a new field in a access table using ADOX, and tell it
to be a random autoincrement field. It must be using ADOX, and it must
generate a random field similar to selecting random autonumber
directly in access.
Answer  
Subject: Re: Autonumber Field in Microsoft Access database
Answered By: iaint-ga on 18 Oct 2002 03:22 PDT
Rated:5 out of 5 stars
 
Hi gravey

I found an article which indicates that what you want to do *is*
possible, but it's not a simple procedure:

"[it wasn't] appropriate for the designers of ADOX to include an
AutoNumber or IdentityColumn property of the Column object. Instead,
to gain access to this data-source-specific functionality, you must
use dynamic properties."
http://www.devx.com/upload/free/features/vbpj/1999/06jun99/jm0699/jm0699.asp

A couple of paragraphs later the same page gives some sample code for
creating an AutoIncrement field:

   Set col = New ADOX.Column
   Set col.ParentCatalog = cat
   With col
      .Type = adInteger
      .Name = "ID"
      .Properties("Autoincrement") = True
   End With
   tbl.Columns.Append col

OK, but you want to make this generate a *random* number
automatically. A little more searching locates an archived thread of
posts which reveals what else we need to add within the With..End With
block:
http://p2p.wrox.com/archive/pro_vb/2001-09/12.asp

      .Properties("Default").Value = "GenUniqueID()"
      .Properties("Fixed Length").Value = True
      .Properties("Jet OLEDB:AutoGenerate").Value = True

I hope this lets you achieve what you require, and good luck with the
rest of your application development!

Regards
iaint-ga


Search criteria (on Google):
adox autonumber
adox column autonumber random
gravey-ga rated this answer:5 out of 5 stars
Thanks for the answer, sorry i took a while to try it, but it does work.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy