473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to update a pointer from one table to another

I have a table containing an Address list, in which the name, street address, phone numbers etc. are spelt out in full but the suburb is recorded simply as a pointer to a Suburbs table containing the suburb name, state and postcode. Because of major changes it has now been necessary to replace the Suburbs table with a new one in which the key fields (Suburb_ID) are different from the previous version, so I need to replace all the pointers in the Address table.

I have made a lookup table containing for each suburb its old Suburb_ID (OSID) and the new one (NSID).

I have created a Sub to loop through the Address table, but I can't get the replacement to work. I tried a query in which the Address table and the Lookup table were linked, but that didn't work. My latest attempt uses a DLookup of the Lookup table, but that doesn't work either. Can anyone suggest a better way?

PS. Here is the code for my latest attempt. The address table is called "Venues" and the lookup table is called "ConvertSuburbID".
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_Click()
  2.  
  3. Dim rs As DAO.Recordset, TempID As Long
  4. Set rs = CurrentDb.OpenRecordset("Venues")
  5.  
  6. If Not (rs.EOF And rs.BOF) Then
  7.     rs.MoveFirst
  8.     Do Until rs.EOF = True
  9.         rs.Edit
  10.         TempID = rs!Suburb_ID
  11.         rs!Suburb_ID = DLookup("NSID", "ConvertSuburbID", "OSID=TempID")
  12.         rs.Update
  13.         rs.MoveNext
  14.     Loop
  15. Else
  16.     MsgBox "There are no records in the recordset."
  17. End If
  18.  
  19. rs.Close                      'Close the recordset
  20. Set rs = Nothing              'Clean up
  21. End Sub
Apr 19 '18 #1

✓ answered by NeoPa

You should be able to do this in a single UPDATE query.

Here's my guess at what you need. This is only possible in as far as you've included the correct details in your question with which to work (Well done) :
Expand|Select|Wrap|Line Numbers
  1. UPDATE [Venues]
  2.        INNER JOIN
  3.        [ConvertSuburbID]
  4.     ON [Venues].[Suburb_ID]=[ConvertSuburbID].[OSID]
  5. SET    [Venues].[Suburb_ID]=[ConvertSuburbID].[NSID]

8 1596
NeoPa
32,556 Expert Mod 16PB
You should be able to do this in a single UPDATE query.

Here's my guess at what you need. This is only possible in as far as you've included the correct details in your question with which to work (Well done) :
Expand|Select|Wrap|Line Numbers
  1. UPDATE [Venues]
  2.        INNER JOIN
  3.        [ConvertSuburbID]
  4.     ON [Venues].[Suburb_ID]=[ConvertSuburbID].[OSID]
  5. SET    [Venues].[Suburb_ID]=[ConvertSuburbID].[NSID]
Apr 20 '18 #2
Brilliant!
I had tried an update query before I tried the Sub, but had obviously created it wrongly and couldn't get it to work.
Thank you very much for your help.
Peter.
(By the way, I am also the user "petrol" (Peter O'L) from 2017. I changed my email address and forgot the old password, so I had to create a new user. The old one can now be deleted.)
Apr 20 '18 #3
NeoPa
32,556 Expert Mod 16PB
You're welcome Peter.
Petrol2:
By the way, I am also the user "petrol" (Peter O'L) from 2017. ... The old one can now be deleted.
I thought you probably were. Not that it's as simple as you seem to imagine. We can't just delete accounts.
I'll see what I can get done for you. It's probably much better to re-use the old account than to work with the new one. I'll get back to you.
Apr 20 '18 #4
NeoPa
32,556 Expert Mod 16PB
The owner has said he'll look into this for you Peter. Look out for emails in either account or a PM in here. He may need extra info from you first before he can fix it.

I don't need to warn you about sharing any info in the forum area. His ID's Niheel and you can be confident of sharing any info with him as long as it's in the PM area.
Apr 25 '18 #5
Many thanks for that, NeoPa. But do tell Niheel not to waste too much of his precious time on it. The new account works just as well, so I guess the only benefit of merging them is to get the statistics right. Is this important?

By the way, I had to close the old email account because of unavailability of the ISP when we moved house. So I'm no longer able to access anything sent to the optusnet address.
Apr 25 '18 #6
NeoPa
32,556 Expert Mod 16PB
Yes. Statistics are important. Niheel will set the new address to the old account and allow you, and everyone else, to continue to work with you on your old account.

Sometimes we look up the history of a poster to get an idea of what we're likely to be dealing with. Information can always be helpful.

PS. I expect Niheel, when he's finished, will delete these last three posts (from #5 onwards) as they're just unrelated chatter that is irrelevant to the thread. Only when you're all sorted out though.
Apr 25 '18 #7
Thanks. I'll be going overseas next Tuesday (actually to England, where you are - I live in Brisbane) so may be very slow to see and respond to any posts after that date.
Apr 25 '18 #8
Thank for share us this. Nice artilce
Apr 26 '18 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Julie Paten | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** Hello, I am using sql+ to try and update a table and am having some trouble. Below is a select statement with the result I want...
1
by: Caroline | last post by:
I need to update a table by copying a column from another table (having the same structure, but on another database), from the record having the same primary key. 1 - What is the correct...
0
by: EKL | last post by:
Hi, I'm making a sort of Customer and Orders database in MS Access 2003. My problem is that I wish to update the table "tblTransaction" based on changes made in the table "tblOrderDetails"....
3
by: Mark A | last post by:
In the DB2 Admin Client (8.2.4), when the results of a query are displayed in the grid that looks like a spreadsheet (using Command Editor or double click on table name in Control Center). The data...
1
by: Sharon | last post by:
Hello All, Is it possible to update Sql Table through DataGrid. I have a DataGrid which is being populated through a stored procedure, all i wanted to do is to update one field...
1
by: Seemaraj | last post by:
I have doubt in VB.Net on how to update the records in table. I m using MS Access database. I have a table named len_graph with 9 fields like...
5
by: sensreview | last post by:
Hello, I need help in selecting a value from combo list thru one lookup table and update different table on MS access form. For eg; I have a lookup table of usernames, I need to use this...
1
by: lunas | last post by:
hi i have to update a table based on a criteria with value selected from another table. i am writting a java progg for it . i just want to know can it be done with one statement. my purpose is ...
3
by: ma | last post by:
Hello, I have two update Panel in my page. I want to update one of these update panels from another one. How can I do this? How can I force the whole page to be updated from a button inside an...
9
by: jgitaunjoroge | last post by:
Hi All, Am trying to update one table with another tables value where both tables have a common relationship. my code is a below. DoCmd.RunSQL "update customer set customer.paid" =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.