Results 1 to 4 of 4
  1. #1
    DavidAlan is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    4

    Create module to add field

    I have a table (IncdSummary) with a poorly formed date field ([DISPTIME]which has a date plus junk). The following query gets me the date I need:

    SELECT Trim(Left([DISPTIME],InStr([DISPTIME]," "))) AS [Date], CDate([Date]) AS MyDate, DatePart("m",[Mydate]) AS DM, DatePart("yyyy",[Mydate]) AS DY, DatePart("d",[Mydate]) AS DD, [DY] & Format([dm],"00") & Format([dd],"00") AS DateNumeric


    FROM IncdSummary;

    This takes a value of 7/6/2010 00:12:15pm and returns 20100706 as a numneric value as needed.

    Can I use this in a module to add a numeric field to IncdSummary table. I have no idea how to create of format a module.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'm not clear on what you're trying to achieve. I assume you don't actually want to add a new field to a table. I'd guess you want a function that accepts the poorly formatted field as an input and returns the numeric value. That would be fairly simple. This should give you a start on the function:

    http://www.baldyweb.com/Function.htm

    In your function, you would just use one or more variables to keep track of your values as you processed them. In fact, you could probably just get to the CDate() part, then use the Format() function:

    Format(DateValueHere, "yyyyddmm")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    DavidAlan is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    4
    actually DO want to add the field to the table (as a numeric field) - data is eventually imported into an ARC GIS .shp file and has to be queried thru an ARC web app. Have to query as a numeric field in order to accomplish what is needed. Seems the simplest way would be to import the clean data as needed rather that import the squirrelly stuff into ARC, then manipulate thru GIS.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can't you just add the field in table design view once and be done with it? It's unusual (but doable) to add fields in code. If you really need to do it through code, you can either execute a DDL query:

    ALTER TABLE...

    or use a DAO TableDef in VBA code.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 5
    Last Post: 06-07-2010, 12:20 PM
  2. Replies: 3
    Last Post: 04-26-2010, 11:38 AM
  3. create new column-name it from form field
    By hyperionfall in forum Forms
    Replies: 6
    Last Post: 03-04-2010, 01:53 PM
  4. Urgent issue! Create field for intervals
    By Bjorn in forum Queries
    Replies: 3
    Last Post: 02-10-2010, 10:26 AM
  5. How to Create Field in Template
    By Jonathan in forum Access
    Replies: 1
    Last Post: 01-30-2009, 02:00 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