Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Insert statement
Hamish 
    
14 years ago
Hi Richard,

After a long day of extensive playing around, I have finally found a work around of what I needed to have done. I thank you for your time in providing me with the guidance on how to go about this.

I was about to give up completely and needed some assistance, hence I have posted my query through to your Tech Help service. Could you please ignore my request.

I apologies for the inconvenience caused.

Regards

Hamish


Reply from Richard Rost:

No problem. I just found your question in TechHelp. I'll post the solution here for everyone else's benefit in case they were following the thread:

In my case using the two tables examples below. How do I get the ID field into Table 1 using VBA code.

Table 1
ID VendorNumber VendorName Inventory InventoryValue
1412269 Colgate Palmolive 400 $500,000.00
1428757 Reckitts
1429444 Natures Organics
1427036 Procter and Gamble 350 $400,000.00

Table 2. ID's from this table needs to be inserted into Table 1 ID field
ID VendorNumber VendorName
1 1427036 Procter and Gamble
2 1428757 Reckitt Benckiser
3 1429444 Nature Organics
4 1412269 Colgate Palmolive




OK, this makes a lot more sense. :)

Create an ID field in Table1, let's call it ID2 (since it's table 2's ID).

Make a recordset and loop through all of the records in Table 1, looking up the ID from Table 2 as you go:

[this code is from memory, I haven't tested it]

dim db as database
dim rs as recordset
set db = currentdb()
set rs = db.openrecordset("Table1",dbopendynaset)
while not rs.eof
rs!ID2 = Nz(Dlookup("ID","Table2","VendorNumber=" & rs!VendorNumber)
rs.movenext
wend
rs.close
set rs = nothing
set db = nothing

Basically this says, loop through all of Table 1's records. For each record, look up the ID field from Table 2 where the Vendor Number is equal to the Vendor Number of the current record in Table 1.

Now, you might run into issues if any of the values are NULL, but if that's the case you can wrap it inside of an NZ function and don't set the value.

Hope this helps.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/17/2026 8:47:03 AM. PLT: 1s