Setting Field Attributes 
Author Message
 Setting Field Attributes

Greetings All:

Using Access for Windows 95, my goal is to use Visual Basic to add an
autonumber field to a table.

Access "auto-numbering" documentation details adding the field using the
table design window.  The "TypeProperty" topic does not discuss
auto-numbering fields.  Are there no constants similar to "dbText" for
creating auto-numbering fields?

God Bless,
Pierre



Tue, 27 Jan 2004 06:14:59 GMT  
 Setting Field Attributes
You don't say whether you are using DAO or ADOX in your VB program, so it's
difficult to answer.  One thing that I can tell you right off the bat is
that the autonumber fields have a field type of long interger.  There is a
separate property that you have to use to make your long integer field an
autonumber one.


Quote:
> Greetings All:

> Using Access for Windows 95, my goal is to use Visual Basic to add an
> autonumber field to a table.

> Access "auto-numbering" documentation details adding the field using the
> table design window.  The "TypeProperty" topic does not discuss
> auto-numbering fields.  Are there no constants similar to "dbText" for
> creating auto-numbering fields?

> God Bless,
> Pierre



Tue, 27 Jan 2004 06:54:42 GMT  
 Setting Field Attributes
(I may be wrong but) I think when Pierre wrote VB, he actually meant VBA for
Access95 (hence DAO).

To add an AutoNumber Field into an existing Table (in A97, not sure about
A95), I normally use the Jet-SQL statement "ALTER TABLE" and the Reserved
Word "Counter" (or "AutoIncrement") to specify an AutoNumber Field.

Check Your A95 Help on the above Keywords see if it is applicable to A95.

HTH
Van T. Dinh


Quote:
> You don't say whether you are using DAO or ADOX in your VB program, so
it's
> difficult to answer.  One thing that I can tell you right off the bat is
> that the autonumber fields have a field type of long interger.  There is a
> separate property that you have to use to make your long integer field an
> autonumber one.



> > Greetings All:

> > Using Access for Windows 95, my goal is to use Visual Basic to add an
> > autonumber field to a table.

> > Access "auto-numbering" documentation details adding the field using the
> > table design window.  The "TypeProperty" topic does not discuss
> > auto-numbering fields.  Are there no constants similar to "dbText" for
> > creating auto-numbering fields?

> > God Bless,
> > Pierre



Tue, 27 Jan 2004 08:44:46 GMT  
 Setting Field Attributes

Quote:

>Greetings All:

>Using Access for Windows 95, my goal is to use Visual Basic to add an
>autonumber field to a table.

>Access "auto-numbering" documentation details adding the field using the
>table design window.  The "TypeProperty" topic does not discuss
>auto-numbering fields.  Are there no constants similar to "dbText" for
>creating auto-numbering fields?

>God Bless,
>Pierre

Pierre

There are two different ways of creating AutoNumber fields in an existing table
- using SQL or using DAO. Below are methods of both:

Sub sAddAuto1()
    Dim db As Database
    Dim strSQL As String
    Set db = DBEngine(0)(0)
    strSQL = "ALTER TABLE [tblDate] ADD COLUMN FieldPK COUNTER;"
    db.Execute strSQL
    Set db = Nothing
End Sub

Sub sCreate2()
    Dim db As Database
    Dim tdf As TableDef
    Dim fld As Field
    Set db = DBEngine(0)(0)
    Set tdf = db.TableDefs("tblDate")
    Set fld = tdf.CreateField("FieldPK", dbLong)
    fld.Attributes = dbAutoIncrField
    tdf.Fields.Append fld
    db.TableDefs.Refresh
    Set fld = Nothing
    Set tdf = Nothing
    Set db = Nothing
End Sub

Whilst the SQL method appears easier, remember that quite a lot of table/field
properties cannot be set using this method, and you would need to use DAO
instead.

Jon

Access tips & tricks - http://www.applecore99.com
Microsoft Access webring -
http://nav.webring.yahoo.com/hub?ring=microsoftaccess



Tue, 27 Jan 2004 13:17:02 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Setting Field Attributes

2. Setting Field Attributes

3. Programmatically setting field attributes with DAO

4. Setting field attribute dbHyperlinkField

5. Access97 Field Attributes that are not in the Attributes collection of that Field

6. Setting the field attribute

7. Set File Attributes

8. setting procedure attribute NewEnum to -4??

9. Automated Utility to Set Excel Attributes

10. Set tables hidden attribute from code


 
Powered by phpBB® Forum Software © phpBB Group