Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Number

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Anybody can tell me that how to create Auto Number in my Data Field in VB?
 
Do you mean, how do you dynamically create an autonumber field when adding fields to an Access database from VB??
 
I assume you're using ADO with an access database...

You need to access one of the dynamic properties of the field object in question. ADO objects have two kinds of properties - built-in and dynamic. Built-in properties are defined by ADO itself and are assigned to all objects. Dynamic properties are specific to the data provider itself. AutoNumber fields belong to this second category.

It is actually quite simple - dynamic properties are accessed via the "Properties" property of whatever object you're interested in. In your case, your object is a field, and the dynamic property you are interested in is called "ISAUTOINCREMENT".

So....

If your field is called 'id', and you are currently looking at this via, say, a recordset called 'rs', then you would achieve what you want by

rs("id").Properties("ISAUTOINCREMENT") = True

NB. I would expect the normal restrictions to apply to this ie. I don't think it would allow you to set this property if there are any records in the table already, for example.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top