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
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:
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.Code:UPDATE tblAddress SET tblAddress.Address3 = [City] & ", " & [State] & ", " & [Zip];
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.
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks