A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Help with Update Query



 
 
Thread Tools Display Modes
  #1  
Old April 19th, 2010, 04:13 PM posted to microsoft.public.access
Chuck W[_2_]
external usenet poster
 
Posts: 98
Default Help with Update Query

Hi,
I have a table called tblLocations that has fields such as LocationID
(autonumber) and UnitID (number). I also have a table called tblMonths1 that
has LocationID (number). I just created a field called UnitID. I want to
run an update query that will match the LocationIDs from the two tables and
then fill in the values for the newly created UnitID field in the tblMonths1
from tblLocations. Can someone help?

Thanks,

  #2  
Old April 19th, 2010, 04:47 PM posted to microsoft.public.access
Daryl S[_2_]
external usenet poster
 
Posts: 881
Default Help with Update Query

Chuck -

Remember to back up your data before testing any new action queries. This
SQL should work for you (untested):

Update tblMonths1
Set [UnitID] = (Select [UnitID] from tblLocations where
tblLocations.LocationID = tblMonths1.LocationID)

--
Daryl S


"Chuck W" wrote:

Hi,
I have a table called tblLocations that has fields such as LocationID
(autonumber) and UnitID (number). I also have a table called tblMonths1 that
has LocationID (number). I just created a field called UnitID. I want to
run an update query that will match the LocationIDs from the two tables and
then fill in the values for the newly created UnitID field in the tblMonths1
from tblLocations. Can someone help?

Thanks,

  #3  
Old April 19th, 2010, 04:53 PM posted to microsoft.public.access
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Help with Update Query

BACKUP DATABASE BACKUP DATABASE BACKUP DATABASE
There is really no need to duplicate the data UnitID in a second table -
just join tblLocations in each query and you will have it.
After you backup then try this --
UPDATE tblMonths1 INNER JOIN tblLocations ON tblMonths1.LocationID =
tblLocations.[LocationID] SET tblMonths1.UnitID = [LocationID].[UnitID];

--
Build a little, test a little.


"Chuck W" wrote:

Hi,
I have a table called tblLocations that has fields such as LocationID
(autonumber) and UnitID (number). I also have a table called tblMonths1 that
has LocationID (number). I just created a field called UnitID. I want to
run an update query that will match the LocationIDs from the two tables and
then fill in the values for the newly created UnitID field in the tblMonths1
from tblLocations. Can someone help?

Thanks,

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:54 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.