Results 1 to 6 of 6
  1. #1
    Join Date
    May 2003
    Location
    Costa Rica
    Posts
    40

    Unhappy Unanswered: Convert autonumeric field to numeric field

    I have an autonumeric field EMBARG into the table INFORME2. I need to change this autonumeric field EMBARG into NUMERIC field using a module in Visual Basic for Microsoft Access. Can someone help me, please!!!!.
    Last edited by Manuel Gimenez; 06-09-03 at 16:32.

  2. #2
    Join Date
    Jan 2003
    Location
    Vietnam
    Posts
    188
    can you give us an example of exactly what you wanna do

    cheers
    qha_vn

  3. #3
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    If this is one field that needs to be changed one time - why not do this through design mode? I think that might be what qha_vn is alluding to.

    Code to change tabledefs can be tricky, so sometimes the quickest solution is the best.

    But I agree with qha_vn let us know what you want to do and the event that would trigger such code and we can come up with a solution.

  4. #4
    Join Date
    May 2003
    Location
    Costa Rica
    Posts
    40

    Unhappy Change autonumeric field into numeric field

    I have a table INFORME2. In this table I created an autonumeric field called "N EMBARGADO" using the following function:
    Dim dbForTable As DAO.Database
    Dim bFieldExists As Boolean
    Dim fldNew As New DAO.Field
    Dim intField As Integer
    Dim strTableName As String
    Dim strFieldName As String
    Set dbForTable = CurrentDb
    strTableName = "INFORME2"
    strFieldName = "N EMBARGADO"
    bFieldExists = False
    Set fldNew = dbForTable.TableDefs(strTableName).CreateField(str FieldName, dbLong)
    fldNew.Attributes = 17
    dbForTable.TableDefs(strTableName).Fields.Append fldNew
    CurrentProject.Connection.Execute "CREATE UNIQUE INDEX PrimaryKey ON INFORME2([N EMBARGADO]) WITH PRIMARY;"
    dbForTable.Close
    Set dbForTable = Nothing

    This procedure creates the AUTONUMERIC field "N EMBARGADO" into the table INFORME2. After that I make some other procedures (run macro, etc). Now I need to convert this autonumeric field into a NUMERIC FIELD (no increments) in a visual basic module for Microsoft Access. Doing it manually it is very easy, just enter into the table INFORME2 and in the type change "Autonumeric" with "Numeric", but the problem is that I need to do it in a visual basic module for Microsoft Access. Can you help me please.

  5. #5
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    create the field first, then ALTER TABLE table1 ADD INDEX....

  6. #6
    Join Date
    Dec 2003
    Posts
    7
    I find answer:

    If use external base answer is:

    myBase.Execute "ALTER TABLE " & myTable & " ALTER COLUMN " & myField & " INT;"

    not

    DoCmd.RunSQL ("ALTER TABLE " & myTable & " ALTER COLUMN " & myField & " INT;")

    thanks for all
    Gregorek
    Last edited by Gregorek; 12-18-03 at 07:53.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •