Modify Data type in Access Macro from text to number

Posted on 2007-10-10
Last Modified: 2013-11-27
I have a process that I would like to automate.  The process is using an access table that has a field that was imported in as "text".  I would like to change the data type to number.  I can manually do it by just going into the the table.  What is the code to modify the data type FieldA from "text" to "number"?
Question by:morinia
    LVL 119

    Accepted Solution

    currentdb.execute "alter table NameOftable alter column NameofField number"
    LVL 44

    Expert Comment

    by:Leigh Purvis
    That'll do it.  Though IMHO you should be pretty precise about the data type you want.
    The above will give you a Double number type by default.  Which is OK if you want it - but
    CurrentDb.Execute "ALTER TABLE TableName ALTER COLUMN FieldA Double"
    would be more explicit.
    And of course if you wanted a long integer then you should be specific about that:
    CurrentDb.Execute "ALTER TABLE TableName ALTER COLUMN FieldA Integer"
    An integer:
    CurrentDb.Execute "ALTER TABLE TableName ALTER COLUMN FieldA SmallInt"

    and so on.
    Same idea though - and for a single operation likely the best choice.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now