Results 1 to 8 of 8
  1. #1
    Leonidsg is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    68

    Change multiple field's properties from Long Integer to Decimal

    Hello,

    I was wondering if it is possible to batch edit field properities. I have many fields that are number fields but I need change the properties from long integer to decimal.



    Thank you,
    Lenny

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    on a table or on a form?

    either is possible but radically different in approach.

  3. #3
    Leonidsg is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    68
    That's a good question. I guess I have a lot number fields on a table which are inputted via a form. If the number is 9.46 I would like it to remain that way. The problem is I have many fields and don't want to change the properties of each of them one by one.

    Thank you for the help.
    Lenny

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    so it's the properties on BOTH your form AND your TABLE?

  5. #5
    Leonidsg is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    68
    Yes that is correct.

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    This code will change any field that's currently integer or long integer to double in your table you just have to substitute your table name where you see "table1".

    BEWARE, if you have an autonumber field as your PK this will change the datatype to double. You will have to program an exception into your code if you do have an autonumber PK field.

    Code:
    Dim tdf As TableDef
    Dim fld As Field
    Dim db As Database
    Dim sSQL As String
    dim sTableName as string
    
    
    Set db = CurrentDb
    sTableName = "Table1"
    Set tdf = db.TableDefs(stablename)
    
    For Each fld In tdf.Fields
        Debug.Print fld.Name & "  " & fld.Type
        
        If fld.Type = 4 Or fld.Type = 10 Then
            sSQL = "ALTER TABLE " & stablename & " ALTER COLUMN " & fld.Name & " double"
            db.Execute sSQL
        End If
    
    Next fld
    set db = nothing
    As far as changing the formats on a from, just select all the relevant fields and change them to general number through the properties box. You should be able to do all of them in one shot after you've selected them.

  7. #7
    Leonidsg is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    68
    I'm sorry for my stupidity, would you mind telling me where this code is inserted. Thank you.

  8. #8
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    just create a module and paste the code into the module (macros and modules I think are part of the same ribbon option in access 2010 but I'm not 100% sure)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 11-14-2012, 01:06 PM
  2. Using DCount with Long integer
    By Dominaz in forum Access
    Replies: 5
    Last Post: 12-06-2011, 05:22 AM
  3. Adding column as INTEGER makes it a long integer?
    By luckycharms in forum Programming
    Replies: 2
    Last Post: 10-20-2010, 02:47 PM
  4. Replies: 3
    Last Post: 04-12-2009, 05:11 PM
  5. Replies: 1
    Last Post: 06-09-2006, 05:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums