get type for autonumber in VBA for Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moni85
    New Member
    • Nov 2008
    • 3

    get type for autonumber in VBA for Access

    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:
    Code:
    Set RecTableSrc = DBSrc.OpenRecordset(StrTableName, DB_OPEN_DYNASET)
      Set RecTableDst = DBDst.OpenRecordset(StrTableName, DB_OPEN_DYNASET)
    .....
    RecTableSrc.MoveFirst
    Do Until RecTableSrc.EOF
          RecTableDst.FindFirst strSearch
          RecTableDst.Edit
          For iFieldCnt = 0 To RecTableSrc.Fields.count - 1
              RecTableDst(RecTableSrc(iFieldCnt).Name) = RecTableSrc(iFieldCnt)
          Next iFieldCnt
          RecTableDst.Update
    Loop
    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:
    Code:
    CBool(RecTableSrc(iFieldCnt).Attributes = dbAutoIncrField) = False
    TypeName(RecTableSrc(iFieldCnt).Type) = dbInteger
    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
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hello.

    Use bitwise "AND" instead of "=" operator

    Code:
    If RecTableSrc(iFieldCnt).Attributes AND dbAutoIncrField THEN ....
    Regards,
    Fish

    Comment

    • moni85
      New Member
      • Nov 2008
      • 3

      #3
      thank you so much.
      It works.

      Comment

      • FishVal
        Recognized Expert Specialist
        • Jun 2007
        • 2656

        #4
        You are welcome.

        Best regards,
        Fish.

        Comment

        Working...