+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    04-27-2009
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007
    Posts
    6

    combining columns into 1 access

    I need to take 3 columns from 1 table and combine into 1 column on another table. Example City column-State column-Zip column to Address 3 column which is City, State, Zip. Does anyone know how to do this in a update query in Access?

    Thanks

  2. #2
    Forum Moderator ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2003 & 2010
    Posts
    1,797

    Re: combining columns into 1 access

    Hi mugs62,

    If you're just learning how to build an Update query, or doing homework, or whatever, then... no problem, here's the SQL of what you described:

    Code:
    UPDATE tblAddress SET tblAddress.Address3 = [City] & ", " & [State] & ", " & [Zip];
    However, you should note that you would not usually do something like this in a table. You'd be far better off building your combined address in a select query, and using it's result where-ever you need it in your database (i.e. on forms or in reports, etc.). Normally, tables shouldn't store "calculated" fields based on other fields.

    Otherwise, Enjoy!

    Cheers,
    Docendo discimus.

    Please consider:
    • Thanking those who helped you. Click the reputation icon in the contributor's post and add Reputation.
    • Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Forum Administrator
    Join Date
    03-18-2009
    Location
    India
    MS-Off Ver
    2003,2007
    Posts
    222

    Re: combining columns into 1 access

    This is the way to create table with two fields

    Code:
    Sub NewDatabase()
        Dim wspDefault As Workspace, dbs As Database
        Dim tdf As TableDef, fld1 As Field, fld2 As Field
        Dim idx As Index, fldIndex As Field
    
        Set wspDefault = DBEngine.Workspaces(0)
        ' Create new, encrypted database.
        Set dbs = wspDefault.CreateDatabase("Newdb.mdb", _
            dbLangGeneral, dbEncrypt)
        ' Create new table with two fields.
        Set tdf = dbs.CreateTableDef("Contacts")
        Set fld1 = tdf.CreateField("ContactID", dbLong)
        fld1.Attributes = fld1.Attributes + dbAutoIncrField
        Set fld2 = tdf.CreateField("ContactName", dbText, 50)
        ' Append fields.
        tdf.Fields.Append fld1
        tdf.Fields.Append fld2
        ' Create primary key index.
        Set idx = tdf.CreateIndex("PrimaryKey")
        Set fldIndex = idx.CreateField("ContactID", dbLong)
        ' Append index fields.
        idx.Fields.Append fldIndex
        ' Set Primary property.
        idx.Primary = True
        ' Append index.
        tdf.Indexes.Append idx
        ' Append TableDef object.
        dbs.TableDefs.Append tdf
        dbs.TableDefs.Refresh
        Set dbs = Nothing
    End Sub
    ExlGuru

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0