Connecting Tech Pros Worldwide Forums | Help | Site Map

get type for autonumber in VBA for Access

Newbie
 
Join Date: Nov 2008
Posts: 3
#1: Nov 18 '08
Hello,

I am trying to update a lot of tables. Some of them have an autonumber that is not unique or primary key(this is the actual implementation and I whould rather not change it).
When I am trying to update the auto number I receive this error:
"Field cannot be updated."
I know that auto number can not be manually updated in access and I am not trying to do that. I want to update everything else and leave the auto number fields.
The code:
Expand|Select|Wrap|Line Numbers
  1. Set RecTableSrc = DBSrc.OpenRecordset(StrTableName, DB_OPEN_DYNASET)
  2.   Set RecTableDst = DBDst.OpenRecordset(StrTableName, DB_OPEN_DYNASET)
  3. .....
  4. RecTableSrc.MoveFirst
  5. Do Until RecTableSrc.EOF
  6.       RecTableDst.FindFirst strSearch
  7.       RecTableDst.Edit
  8.       For iFieldCnt = 0 To RecTableSrc.Fields.count - 1
  9.           RecTableDst(RecTableSrc(iFieldCnt).Name) = RecTableSrc(iFieldCnt)
  10.       Next iFieldCnt
  11.       RecTableDst.Update
  12. Loop
  13.  
Into the table I have defined field ID:
Data Type: Autonumber
Field Size: Long Integer
New Values: Increment
Indexed: Yes (Duplicates OK)

What I have:
Expand|Select|Wrap|Line Numbers
  1. CBool(RecTableSrc(iFieldCnt).Attributes = dbAutoIncrField) = False
  2. TypeName(RecTableSrc(iFieldCnt).Type) = dbInteger
  3.  
I have tried with all the properties of the field but they seem to be the same as for an integer.

Can you please tell me how to find out whether my field is autonumber or not?

FishVal's Avatar
Expert
 
Join Date: Jun 2007
Location: Israel
Posts: 2,584
#2: Nov 18 '08

re: get type for autonumber in VBA for Access


Hello.

Use bitwise "AND" instead of "=" operator

Expand|Select|Wrap|Line Numbers
  1. If RecTableSrc(iFieldCnt).Attributes AND dbAutoIncrField THEN ....
  2.  
Regards,
Fish
Newbie
 
Join Date: Nov 2008
Posts: 3
#3: Nov 18 '08

re: get type for autonumber in VBA for Access


thank you so much.
It works.
FishVal's Avatar
Expert
 
Join Date: Jun 2007
Location: Israel
Posts: 2,584
#4: Nov 18 '08

re: get type for autonumber in VBA for Access


You are welcome.

Best regards,
Fish.
Reply