473,396 Members | 1,755 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,396 software developers and data experts.

how to update one table based on values in other table

i have table consider table 1 which contains employee code which is unique and date of leaving
and there is another table consider table 2 where employee code is foreign key and contains Date of leaving(which is blank).
i want on click of button all the employee code present in table 2 to get updated with date of leaving present in table 1
i am trying following code
Expand|Select|Wrap|Line Numbers
  1. Private Sub YOUR_COMMAND_Click()
  2. Dim strSql As String
  3.  
  4. strSql = "UPDATE [TABLE_2]" & _
  5.     "SET [TABLE_2].Date_of_Leaving = '"table_1.[DATE_OF lEAVING]'" WHERE EMP_CODE= ' "TABLE1.EMP_CODE " '"
  6.  
  7. DoCmd.RunSQL strSql
  8.  
  9.  
but its not working
PLZ HELP
Dec 4 '13 #1
3 1210
zmbd
5,501 Expert Mod 4TB
Might I inquire why?
One does not normally duplicate data in a well normalized database.
Dec 4 '13 #2
Just need to know whether its possible
Dec 5 '13 #3
zmbd
5,501 Expert Mod 4TB
it's possible.
"cheat" on the sql
Do this first using the query editor.
I'll make a copy of both tables, use the QE to create a select query that returns the correct records, then convert to an update and run on the copies. If all goes well, I then switch to the SQL view and copy the sql for use in the VBA code altering to suit variables as needed.
HOWEVER< I rarely do this to copy one value from one table to another, especially if there is a related field.
Dec 5 '13 #4

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

Similar topics

2
by: elziko | last post by:
I have two tables TAB_A and TAB_B. I want to update COL_1 in TAB_A to a certain value but only for rows where the value COL_2 in TAB_A is also found in COL_2 of TAB_B. This is what I have but it...
5
by: Mike | last post by:
Here is my situation; I have two tables in a MS-SQL DB. One table with dollar amounts and service codes. I have a second table that I want to move some information into from the first table. The...
2
by: Mark | last post by:
Hello, We currently have a table (access 2000) that has the following values: 706 6789 1 5.11 N N 20040923 792 6592 1 10.05 N N 20040923 795 1605 1 6.30 N N 20040923 807 5817 1 6.33 N N...
3
by: bitoulis | last post by:
Hi, is it possible to use the records of a table as the field names of another table? If yes, how is it done? Thanks in advance Laertes
0
by: Leonardo Gangemi | last post by:
How to align right a table based on another table created dinamically? Leonardo
3
by: turtle | last post by:
I have Two tables (Table1 and Table2). Both tables have a common field called part number. Table 1 contains an extra field that i would like to update table 2 to match if the part number matches....
1
by: zoeb | last post by:
Currently I have a table, and would like the calculate a field in the table by referencing values from another 3 tables. i.e. tblData Index1, Index2, Index3, Value 1 2 3 2...
2
by: tinnu | last post by:
Hi guys.... suggestions needed I have the following tables Table : Temp3 -------------------------- Temp3ID Char1 Char2 1 x1 NULL 2 x1 312 3 ...
1
by: Gugyu | last post by:
I have a table AVI with the following relevant structure: POLY_NUM key LKP SITE1 SITE2 SITE3 Y2BH I have a lookup table SILKP with: LKP
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.