Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 27th, 2004, 04:25 PM
Authorized User
 
Join Date: Jan 2004
Location: Reading, Berksire, United Kingdom.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default AutoNumber Conundrum

My next little stumbling block if anyone here has come accross it.

Using an sql statement to create a table(recordset) with ado (sorry - I was reared on wrox ado in my asp days...) and defining fields and types works just fine until I try to set the first field as type 'autonumber'. It won't wear it. I appreciate I can create this manually and populate it, but I'd prefer to do it dynamically and solve the problem - I can also not figure how to set the first field in the sql to be a primary key - im sure one of you pro's will probably laugh at this!:

Example statement:
localconnection.Execute _
"CREATE TABLE imported(" & _
"trackid AutoNumber," & _ ' tried AUTONUMBER and autonumber too
"Artist VARCHAR(75)," & _
"title VARCHAR(75)," & _
"BPM INTEGER," & _
"Genre VARCHAR(50)," & _
"Track_Year INTEGER," & _
"Version VARCHAR(75)," & _
"Comment VARCHAR(75)," & _
"Album VARCHAR(75)," & _
"Karaoke VARCHAR(75))"

Reply With Quote
  #2 (permalink)  
Old January 27th, 2004, 04:31 PM
Friend of Wrox
 
Join Date: Jul 2003
Location: Houston, Texas, USA.
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is DAO, but maybe you can find the equivalent if this is what you are looking for:

Code:
'*  Create a field; set its properties; add it to the tabledef
    Set fld = tb.CreateField("ID", dbLong)
        fld.OrdinalPosition = 1
        fld.Attributes = dbAutoIncrField
    tb.Fields.Append fld

'*  Create an index and set its properties
    Set idx = tb.CreateIndex("PrimaryKey")
        idx.Primary = True
        idx.Required = True
        idx.Unique = True

'*  Add an index to a field
    Set fld = idx.CreateField("ID")
        idx.Fields.Append fld

'*  Add the index to the tabledef
        tb.Indexes.Append idx


HTH,

Beth M
Reply With Quote
  #3 (permalink)  
Old January 27th, 2004, 07:27 PM
Authorized User
 
Join Date: Jan 2004
Location: Reading, Berksire, United Kingdom.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for taking the time but the DAO route is not of interest to me. I'll dig out my old sams VB books from the attic and find an answer with sql and ado in that.

again - thanks for your time :-)

Reply With Quote
  #4 (permalink)  
Old January 28th, 2004, 06:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Here you go, example of creating table and setting autonumber using ADOX:
http://msdn.microsoft.com/library/en...asp?frame=true
Reply With Quote
  #5 (permalink)  
Old January 28th, 2004, 05:29 PM
Authorized User
 
Join Date: Jan 2004
Location: Reading, Berksire, United Kingdom.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found it half in a sams book (TY database programming with vb6 and half in a forum(http://www.utteraccess.com/forums/ac...ess562187.html): this works! (yipeeeee!!))

localconnection.Execute _
"CREATE TABLE imported(" & _
"trackid INT IDENTITY CONSTRAINT PKimported PRIMARY KEY," & _
"Artist VARCHAR(75)," & _
"title VARCHAR(75)," & _
"BPM INTEGER," & _
"Genre VARCHAR(50)," & _
"Track_Year INTEGER," & _
"Version VARCHAR(75)," & _
"Comment VARCHAR(75)," & _
"Album VARCHAR(75)," & _
"Karaoke VARCHAR(75))"


But hell did I get trouble for my sins. Books were in my loft. Halfway through recovering them the snowstorm and wind took the power out and getting my fat butt down in the dark was fun... suffering for fun....
Reply With Quote
Reply


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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update query conundrum! timoma Access 4 April 1st, 2005 02:04 PM
Help Needed in Autonumber! jamest Access VBA 3 February 3rd, 2005 03:52 PM
Autonumber in a dataset namellac VB.NET 2002/2003 Basics 0 January 13th, 2005 06:23 PM
regarding Autonumber... MuthuAL Classic ASP Databases 2 December 8th, 2004 08:04 AM
Excel VBA - Wordwrap conundrum Shack Excel VBA 1 May 21st, 2004 06:12 AM



All times are GMT -4. The time now is 12:05 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.