Update address from one data Base to another

G

Guest

I currently have 2 data bases with similar information, but different in many
ways. If I change the address in one data base is there a procedure that I
can use to update the address details in the other data base, without having
to manually do this?

Thanks for any help
 
G

Guest

Thanks for that Chris.
As I am really a novice, do I write a new query and compose in SQL mode?
What sort of query would I use to update/change the address details in the
other data base for an existing record that already has address details.
The fields are Unit, Unit Number, Street Name, Suburb.

The two data bases are called MemberP and MemberH and contain similar
information.

How would I write the code as per above.

Sorry, if I am a pain and thanks again for you invaluable support.


Chris2 said:
Roger Bell said:
I currently have 2 data bases with similar information, but different in many
ways. If I change the address in one data base is there a procedure that I
can use to update the address details in the other data base, without having
to manually do this?

Thanks for any help

Roger Bell,

Yes, it is possible to directly refer to tables in other MS Access
Databases from within a Query.

Examples:

CalendarYear is a one-column table (CalendarDate, DATETIME), that I
use for various date testing purposes.

A blank version must exist in the destination database for this query
to work.

INSERT INTO [C:\Documents and Settings\User\My
Documents\SplitTest2.mdb].CalendarYear
(CalendarDate)
SELECT C1.CalendarDate
FROM [C:\Documents and Settings\User\My
Documents\SplitTest1.mdb].CalendarYear AS C1;


You can also conduct JOINs between tables in multiple databases.

SELECT C2.CalendarDate
FROM [C:\Documents and Settings\User\My
Documents\SplitTest1.mdb].CalendarYear AS C1
INNER JOIN
[C:\Documents and Settings\User\My
Documents\SplitTest2.mdb].CalendarYear AS C2
ON C1.CalendarDate = C2.CalendarDate;

This also works for UPDATE and DELETE (and probably SELECT INTO and
TRANSFORM...PIVOT, though I haven't tried those).


Sincerely,

Chris O.
 
C

Chris2

Roger Bell said:
I currently have 2 data bases with similar information, but different in many
ways. If I change the address in one data base is there a procedure that I
can use to update the address details in the other data base, without having
to manually do this?

Thanks for any help

Roger Bell,

Yes, it is possible to directly refer to tables in other MS Access
Databases from within a Query.

Examples:

CalendarYear is a one-column table (CalendarDate, DATETIME), that I
use for various date testing purposes.

A blank version must exist in the destination database for this query
to work.

INSERT INTO [C:\Documents and Settings\User\My
Documents\SplitTest2.mdb].CalendarYear
(CalendarDate)
SELECT C1.CalendarDate
FROM [C:\Documents and Settings\User\My
Documents\SplitTest1.mdb].CalendarYear AS C1;


You can also conduct JOINs between tables in multiple databases.

SELECT C2.CalendarDate
FROM [C:\Documents and Settings\User\My
Documents\SplitTest1.mdb].CalendarYear AS C1
INNER JOIN
[C:\Documents and Settings\User\My
Documents\SplitTest2.mdb].CalendarYear AS C2
ON C1.CalendarDate = C2.CalendarDate;

This also works for UPDATE and DELETE (and probably SELECT INTO and
TRANSFORM...PIVOT, though I haven't tried those).


Sincerely,

Chris O.
 
C

Chris2

Roger Bell said:
Thanks for that Chris.

Roger Bell,

You're welcome! :D

As I am really a novice, do I write a new query and compose in SQL
mode?

You can do this in the query grid by adding any table and typing in
the file path and db name into the Source property of the table (right
click the table in the query grid and select properties).

You can design normally in the query grid after that.


What sort of query would I use to update/change the address details in the
other data base for an existing record that already has address details.
The fields are Unit, Unit Number, Street Name, Suburb.

An UPDATE query.

UPDATE [<your file path>].<your table>
SET <your column> = <whatever value>
WHERE <criteria>

I recommend writing the simplest possible version of an update.

UPDATE [c:\MyDatabases\Mydatabase.mdb].MyTable
SET MyColumn = 1

(You *are* substituting my generic file path, file name, table name,
column name, and value with your own versions of those pieces of
information.)

Once you have written a super-simple update query in the SQL view of a
new MS Access Query, switch to the query grid and work from there by
adding/adjusting column names and criteria so you don't have to worry
too much about the SQL.
The two data bases are called MemberP and MemberH and contain similar
information.

How would I write the code as per above.

In an MS Access Query object in MemberP.mdb:

UPDATE [c:\MyDatabases\MemberH.mdb].MyTable
SET MyColumn = 1

This way, you are updating values over to MemberH.mdb.

Sorry, if I am a pain and thanks again for you invaluable support.

Not at all!


Sincerely,

Chris O.
 
G

Guest

Thanks again Chris.
I will have a go. It is people like you that really make novices like me
understand better and appreciate the time and effort you apply to the
questions on this site.
Keep up your good work
Regards
Roger

Chris2 said:
Roger Bell said:
Thanks for that Chris.

Roger Bell,

You're welcome! :D

As I am really a novice, do I write a new query and compose in SQL
mode?

You can do this in the query grid by adding any table and typing in
the file path and db name into the Source property of the table (right
click the table in the query grid and select properties).

You can design normally in the query grid after that.


What sort of query would I use to update/change the address details in the
other data base for an existing record that already has address details.
The fields are Unit, Unit Number, Street Name, Suburb.

An UPDATE query.

UPDATE [<your file path>].<your table>
SET <your column> = <whatever value>
WHERE <criteria>

I recommend writing the simplest possible version of an update.

UPDATE [c:\MyDatabases\Mydatabase.mdb].MyTable
SET MyColumn = 1

(You *are* substituting my generic file path, file name, table name,
column name, and value with your own versions of those pieces of
information.)

Once you have written a super-simple update query in the SQL view of a
new MS Access Query, switch to the query grid and work from there by
adding/adjusting column names and criteria so you don't have to worry
too much about the SQL.
The two data bases are called MemberP and MemberH and contain similar
information.

How would I write the code as per above.

In an MS Access Query object in MemberP.mdb:

UPDATE [c:\MyDatabases\MemberH.mdb].MyTable
SET MyColumn = 1

This way, you are updating values over to MemberH.mdb.

Sorry, if I am a pain and thanks again for you invaluable support.

Not at all!


Sincerely,

Chris O.
 
G

Guest

I have tried that Chris and when I run the query, it tells me I am updating a
number of rows, but nothing changes.

The SQL of the query designed in the main Data Base is as follows:

UPDATE [D:\PARISH DATABASES\SPEARWOOD\MEMBERSHIP HALL PLANNED
GIVING.MDB].[MAIN TABLE] SET [MAIN TABLE].[Street Name] = [street name];

Where Membership Hall Planned Giving.Mdb is the data base to be updated.

Query Grid:
Field: Street Name; Table: Main Table; Update to [Street Name]; Criteria:
Blank

How does the query know to just update any street name change for a specific
record. I do not really understand the MyColumn = 1 code.

The source property of the table shows: D:\PARISH
DATABASES\SPEARWOOD\MEMBERSHIP HALL PLANNED GIVING.MDB

The data Base I am trensferring the street name from is Membership.mdb
Please help?



Chris2 said:
Roger Bell said:
Thanks for that Chris.

Roger Bell,

You're welcome! :D

As I am really a novice, do I write a new query and compose in SQL
mode?

You can do this in the query grid by adding any table and typing in
the file path and db name into the Source property of the table (right
click the table in the query grid and select properties).

You can design normally in the query grid after that.


What sort of query would I use to update/change the address details in the
other data base for an existing record that already has address details.
The fields are Unit, Unit Number, Street Name, Suburb.

An UPDATE query.

UPDATE [<your file path>].<your table>
SET <your column> = <whatever value>
WHERE <criteria>

I recommend writing the simplest possible version of an update.

UPDATE [c:\MyDatabases\Mydatabase.mdb].MyTable
SET MyColumn = 1

(You *are* substituting my generic file path, file name, table name,
column name, and value with your own versions of those pieces of
information.)

Once you have written a super-simple update query in the SQL view of a
new MS Access Query, switch to the query grid and work from there by
adding/adjusting column names and criteria so you don't have to worry
too much about the SQL.
The two data bases are called MemberP and MemberH and contain similar
information.

How would I write the code as per above.

In an MS Access Query object in MemberP.mdb:

UPDATE [c:\MyDatabases\MemberH.mdb].MyTable
SET MyColumn = 1

This way, you are updating values over to MemberH.mdb.

Sorry, if I am a pain and thanks again for you invaluable support.

Not at all!


Sincerely,

Chris O.
 
J

John W. Vinson

I have tried that Chris and when I run the query, it tells me I am updating a
number of rows, but nothing changes.

The SQL of the query designed in the main Data Base is as follows:

UPDATE [D:\PARISH DATABASES\SPEARWOOD\MEMBERSHIP HALL PLANNED
GIVING.MDB].[MAIN TABLE] SET [MAIN TABLE].[Street Name] = [street name];

Where Membership Hall Planned Giving.Mdb is the data base to be updated.

Query Grid:
Field: Street Name; Table: Main Table; Update to [Street Name]; Criteria:
Blank

How does the query know to just update any street name change for a specific
record. I do not really understand the MyColumn = 1 code.

The source property of the table shows: D:\PARISH
DATABASES\SPEARWOOD\MEMBERSHIP HALL PLANNED GIVING.MDB

The data Base I am trensferring the street name from is Membership.mdb
Please help?

Whoa. You're WAY off track.

First off, there is a syntax for referencing a table in a different database -
but this isn't it.

Secondly, you're updating the value of [Street name] to the value of [Street
name] - that is, updating the value to itself, not changing anything.

I think what you want to do instead is to open your Membership Hall Planned
Giving database. Open the Tables tab on the database. On the menu select
File... Get External Data... Link Tables. Link to the Membership.mdb database
and select the [MAIN TABLE].

I'm not sure just what you want to update. An UPDATE query lets you change the
value of a field in an existing record. Do you have a [MAIN TABLE] in
Membership.mdb, and another [MAIN TABLE] in Membership Hall Planned
Giving.mdb? If so, why? It sounds like you're possibly storing data
redundantly in two different databases. And how do you identify WHICH record
in the Planned Giving database main table needs to be updated, and which
record in Membership should be used to update it???

John W. Vinson [MVP]
 
C

Chris2

Roger Bell said:
I have tried that Chris and when I run the query, it tells me I am updating a
number of rows, but nothing changes.

The SQL of the query designed in the main Data Base is as follows:

UPDATE [D:\PARISH DATABASES\SPEARWOOD\MEMBERSHIP HALL PLANNED
GIVING.MDB].[MAIN TABLE] SET [MAIN TABLE].[Street Name] = [street name];

Where Membership Hall Planned Giving.Mdb is the data base to be updated.

Query Grid:
Field: Street Name; Table: Main Table; Update to [Street Name]; Criteria:
Blank

How does the query know to just update any street name change for a specific
record. I do not really understand the MyColumn = 1 code.

The source property of the table shows: D:\PARISH
DATABASES\SPEARWOOD\MEMBERSHIP HALL PLANNED GIVING.MDB

The data Base I am trensferring the street name from is Membership.mdb
Please help?

Roger Bell,

You can do linked tables, as well, as John Vinson mentioned. That
saves you from having to use the entire path-name\file-name in the
query. I think I misinterpreted, "[...] without having to manually do
this." to mean "so I don't have to create linked tables".

I am going to assume a switch to using linked tables.

The query you gave:

UPDATE [D:\PARISH DATABASES\SPEARWOOD\MEMBERSHIP HALL PLANNED
GIVING.MDB].[MAIN TABLE]
SET [MAIN TABLE].[Street Name] = [street name];

As John Vinson also mentioned, you are using a query in the other
database to order that a table in that other database has one of its
columns be updated with the data that is already in the column.

I assumed you would be adding criteria (i.e. WHERE clause stuff in
SQL).

I also assumed you would be adding another table in the query in the
source database and joining it to the table in the other database to
provide the data for the update.

UPDATE YourLinkedDestinationDatabaseTable AS T1
INNER JOIN
YourSourceDatabaseTable AS T2
SET T1.[Street Name] = T2.[street name];

Or something like that.

(The "AS T1" and "AS T2" are table aliases. We give short names to
the tables so the rest of the query isn't cluttered up with lengthy
names, and for other reasons, as well.)

----------------------------------

If you are storing information in two places, that would be a
additional maintenance factor.

If you are using data acquired from other sources to update your main
database with current information, that is okay (at least to me). It
just means you are keeping your data import/export and transformation
functions in a separate MS Access database.


Sincerely,

Chris O.
 
G

Guest

Thanks, Have done as you suffested with the following code:
UPDATE [MAIN TABLE], [MAIN TABLE1] SET [MAIN TABLE1].[Street Name] = [MAIN
TABLE].[STREET NAME]
WHERE ((([MAIN TABLE].[Envelope Number])=1));
This works, except it updates all Street Names in the data Base, not just
the one relating to the Envelope 1.

Where have I gone wrong again?
Many thanks

Chris2 said:
Roger Bell said:
I have tried that Chris and when I run the query, it tells me I am updating a
number of rows, but nothing changes.

The SQL of the query designed in the main Data Base is as follows:

UPDATE [D:\PARISH DATABASES\SPEARWOOD\MEMBERSHIP HALL PLANNED
GIVING.MDB].[MAIN TABLE] SET [MAIN TABLE].[Street Name] = [street name];

Where Membership Hall Planned Giving.Mdb is the data base to be updated.

Query Grid:
Field: Street Name; Table: Main Table; Update to [Street Name]; Criteria:
Blank

How does the query know to just update any street name change for a specific
record. I do not really understand the MyColumn = 1 code.

The source property of the table shows: D:\PARISH
DATABASES\SPEARWOOD\MEMBERSHIP HALL PLANNED GIVING.MDB

The data Base I am trensferring the street name from is Membership.mdb
Please help?

Roger Bell,

You can do linked tables, as well, as John Vinson mentioned. That
saves you from having to use the entire path-name\file-name in the
query. I think I misinterpreted, "[...] without having to manually do
this." to mean "so I don't have to create linked tables".

I am going to assume a switch to using linked tables.

The query you gave:

UPDATE [D:\PARISH DATABASES\SPEARWOOD\MEMBERSHIP HALL PLANNED
GIVING.MDB].[MAIN TABLE]
SET [MAIN TABLE].[Street Name] = [street name];

As John Vinson also mentioned, you are using a query in the other
database to order that a table in that other database has one of its
columns be updated with the data that is already in the column.

I assumed you would be adding criteria (i.e. WHERE clause stuff in
SQL).

I also assumed you would be adding another table in the query in the
source database and joining it to the table in the other database to
provide the data for the update.

UPDATE YourLinkedDestinationDatabaseTable AS T1
INNER JOIN
YourSourceDatabaseTable AS T2
SET T1.[Street Name] = T2.[street name];

Or something like that.

(The "AS T1" and "AS T2" are table aliases. We give short names to
the tables so the rest of the query isn't cluttered up with lengthy
names, and for other reasons, as well.)

----------------------------------

If you are storing information in two places, that would be a
additional maintenance factor.

If you are using data acquired from other sources to update your main
database with current information, that is okay (at least to me). It
just means you are keeping your data import/export and transformation
functions in a separate MS Access database.


Sincerely,

Chris O.
 
C

Chris2

Roger Bell said:
Thanks, Have done as you suffested with the following code:
UPDATE [MAIN TABLE], [MAIN TABLE1] SET [MAIN TABLE1].[Street Name] = [MAIN
TABLE].[STREET NAME]
WHERE ((([MAIN TABLE].[Envelope Number])=1));
This works, except it updates all Street Names in the data Base, not just
the one relating to the Envelope 1.

Where have I gone wrong again?
Many thanks

Roger Bell,

I left off a line of SQL in my example because I had written directly
before the example:

"I also assumed you would be adding another table in the query in the
source database and joining it to the table in the other database to
provide the data for the update."

I assumed you would use my example, in general, replacing my example
column and table names with yours, and that you would switch to the
query grid, and drag and drop some column names between the displayed
table-boxes in the top of the query grid in order to establish the
appropriate connection.

Doing that would have added the missing line (or lines) of code.

My SQL with the missing line (example version of the missing line):

UPDATE YourLinkedDestinationDatabaseTable AS T1
INNER JOIN
YourSourceDatabaseTable AS T2
ON T1.PrimaryKey = T2.PrimaryKey
SET T1.[Street Name] = T2.[street name];


Where you change "ON T1.PrimaryKey = T2.PrimaryKey" so that my example
column names (PrimaryKey) on each side of the = sign are replaced by
the correct column names in your two tables. If there are multiple
primary key columns, start a new line below ON beginning with AND.

ON T1.PrimaryKey1 = T2.PrimaryKey1
AND T1.PrimaryKey2 = T2.PrimaryKey2

You can also use the query grid to make or change these conditions.


Whenever you run a Query (SELECT, UPDATE, INSERT, DELETE,
SELECT...INTO, TRANSFORM...PIVOT) with more than two tables, you must
instruct the database on what columns are used to "join" the tables
together.*

INNER JOIN means that only rows in both tables where values in both
sets of columns match are "joined".

LEFT JOIN means that all rows in both table are returned, and when a
row in the right-hand table has no match for the specified ON
conditions, NULLS are returned in any output columns for that table.

RIGHT JOIN means that all rows in both table are returned, and when a
row in the left-hand table has no match for the specified ON
conditions, NULLS are returned in any output columns for that table.

"Left" and "right" mean to the left and right of the = sign after ON.
(Operators other than = also apply, so it also means to the left and
right of =>, >=, and <>)


*If you leave off the instructions, the database will join every row
in the first table with every row in the second table. The number of
output rows equals the number of rows in the first table multiplied by
the number of rows in the second table. This is called a Cartesian
Product, and is not used except for very specific queries.


Two example tables:

Items:
ItemID -- Primary Key
ItemName

ItemID, ItemName
1, Popcorn
2, Chips
3, Soda
4, Fillet Mignon

Prices:
PriceID -- Primary Key
ItemID
ItemPrice
StartDate
EndDate

PriceID, ItemID, ItemPrice, StartDate, EndDate
1, 1, 1.00, 06/01/2007, 06/08/2007
2, 2, 3.50, 06/01/2007, 06/08/2007
3, 3, 1.00, 06/01/2007, 06/08/2007

INNER JOIN Example:

SELECT I1.ItemName
,P1.ItemPrice
FROM Items AS I1
INNER JOIN
Prices AS P1
ON I1.ItemID = P1.ItemID
WHERE P1.StartDate >= #06/09/2007#

Returns
ItemName, Price
Popcorn, 1.00
Chips, 3.50
Soda, 1.00

Notice that Fillet Mignon does not appear. There is no = match (after
the ON clause) for ItemID between the two tables.

LEFT JOIN Example:

SELECT I1.ItemName
,P1.ItemPrice
FROM Items AS I1
LEFT JOIN
Prices AS P1
ON I1.ItemID = P1.ItemID
WHERE P1.StartDate >= #06/09/2007#

Returns
ItemName, Price
Popcorn, 1.00
Chips, 3.50
Soda, 1.00
Fillet Mignon, Null

Now Fillet Mignon does appear, even though there is no = match on
ItemID between the two tables. The output column (ItemPrice) from the
"right hand" table (Prices) leaves a Null behind.


DDL SQL (Usable to create the two tables above so you can run these
queries on your own. You will need to manually type in the sample
data noted above.)

CREATE TABLE Items
(ItemID AUTOINCREMENT
,ItemName TEXT(36)
,CONSTRAINT pk_Items
PRIMARY KEY (ItemID)
)

CREATE TABLE Prices
(PriceID AUTOINCREMENT
,ItemID INTEGER NOT NULL
,ItemPrice CURRENCY
,StartDate DATETIME NOT NULL
,EndDate DATETIME
,CONSTRAINT pk_Prices
PRIMARY KEY (PriceID)
,CONSTRAINT fk_Prices_Items
FOREIGN KEY (ItemID)
REFERENCES Items (ItemID)
)


Sincerely,

Chris O.
 
C

Chris2

Chris2 said:
INNER JOIN Example:

SELECT I1.ItemName
,P1.ItemPrice
FROM Items AS I1
INNER JOIN
Prices AS P1
ON I1.ItemID = P1.ItemID
WHERE P1.StartDate >= #06/09/2007#

LEFT JOIN Example:

SELECT I1.ItemName
,P1.ItemPrice
FROM Items AS I1
LEFT JOIN
Prices AS P1
ON I1.ItemID = P1.ItemID
WHERE P1.StartDate >= #06/09/2007#

Whoops. Remove both WHERE lines.


SELECT I1.ItemName
,P1.ItemPrice
FROM Items AS I1
INNER JOIN
Prices AS P1
ON I1.ItemID = P1.ItemID



SELECT I1.ItemName
,P1.ItemPrice
FROM Items AS I1
LEFT JOIN
Prices AS P1
ON I1.ItemID = P1.ItemID


Sincerely,

Chris O.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top