
help i need to join two or more tables to one
There are 3 tables in the database, located in "C:\temp\db1.mdb"
Movimientos, Clientes and Productos. They all share the key fields
MovieID, which means that the fields MovieID is in all of these tables as
the same data type and data size. The relationship between the 3 table is
One-To-One.
Table Movimientos and table Clientes share the field NumCli which means
that the field NumCli resizes in both tables as the same field name, the
same data type and the same data size.
Table Movimientos and table Productos share the field NumProd which means
that the field NumProd resizes in both tables as the same field name, the
same data type and the same data size.
The following code helps to update all records in the table Movimientos
with values from the other 2 tables Clientes and Productos. If the fields
in the table Movimientos are empty or blank, they are filled with new
values. In other sense you may say that the program joints the field
NumCli in the table Clientes and the field NumProd in the table Productors
into the table Movimientos. It can joint as you said in the condition
that, there are already the key field MovieID in the table Movimientos
that is filled with all values.
Create a new and blank project with the default form. On the form, place a
command button and name it cmdUpdate. Copy and paste the following code
into your source code area, and you are ready to run it, pressing F5 key:
Option Explicit
Dim WrkSpc As Workspace
Dim DBase As Database
Dim strSQL As String
Private Sub cmdUpdate_Click()
On Error GoTo AnyErr
Set WrkSpc = CreateWorkspace("", "admin", "")
Set DBase = WrkSpc.OpenDatabase("C:\temp\db1.mdb")
strSQL = "UPDATE (Clientes " & _
"INNER JOIN Movimientos " & _
"ON Clientes.MovieID = Movimientos.MovieID) " & _
"INNER JOIN Productos " & _
"ON Clientes.MovieID = Productos.MovieID " & _
"SET Movimientos.NumProd = [Clientes].[NumCli], " & _
"Movimientos.NumCli = [Productos].[NumProd];"
DBase.Execute (strSQL)
MsgBox "Clientes and Productos are updated in Movimientos", _
vbInformation, "Good News from AnhMy Tran"
Exit Sub
AnyErr:
MsgBox Err.Description, vbCritical, "Bad News from AnhMy Tran"
End Sub
Good luck.
--
Posted via CNET Help.com
http://www.help.com/