I currently have the following VBA access function:
Private Function MapFields(tableNameTemp As String, tableName As String, commonField As String, newTableName) sqlJoinQuery = "SELECT [" + tableNameTemp + "].[Field1], " & _ "[" + tableNameTemp + "].[Field2], " & _ "[" + tableNameTemp + "].[Field3], " & _ "[" + tableNameTemp + "].[Field4], " & _ "[" + tableName + "].*" & _ " INTO " + newTableName & _ " FROM [" + tableNameTemp & _ "] INNER JOIN [" + tableName & _ "] ON [" + tableNameTemp + "].[" + commonField + "] = [" + tableName + "].[" + commonField + "];" Debug.Print sqlJoinQuery CurrentDb.Execute sqlJoinQuery End Function
To do this, make the table tableName and an internal join with the table newTableName Field1 to Field4 on commonField . Note that Field4 will be the same as commonField , as it must be selected to complete the connection.
To convey my intentional behavior, I must explain how tableNameTemp fields are tableNameTemp . The table below is an example of some of the fields that will be retrieved from tableNameTemp since they appear in the tableNameTemp table.
ββββββββββββββββββββββββββ¦βββββββββ¦βββββββββ¦βββββββββ β Field4 AKA commonField β Field1 β Field2 β Field3 β β βββββββββββββββββββββββββ¬βββββββββ¬βββββββββ¬βββββββββ£ β SA12 β No β No β No β β βββββββββββββββββββββββββ¬βββββββββ¬βββββββββ¬βββββββββ£ β CY84 β No β No β No β β βββββββββββββββββββββββββ¬βββββββββ¬βββββββββ¬βββββββββ£ β CY84 β Yes β No β No β β βββββββββββββββββββββββββ¬βββββββββ¬βββββββββ¬βββββββββ£ β CY84 β No β No β Yes β β βββββββββββββββββββββββββ¬βββββββββ¬βββββββββ¬βββββββββ£ β CY84 β No β Yes β No β β βββββββββββββββββββββββββ¬βββββββββ¬βββββββββ¬βββββββββ£ β EH09 β Yes β No β No β β βββββββββββββββββββββββββ¬βββββββββ¬βββββββββ¬βββββββββ£ β EH09 β No β No β No β ββββββββββββββββββββββββββ©βββββββββ©βββββββββ©βββββββββ
As you can see above, tableNameTemp does not have unique commonField / Field4 values. However, the table with which it will be associated, tableName , has unique commonField / Field4 values. What I intend to do is make sure that for each field in Field1 Field3 , if any of the records has yes , then match yes with the same field in the corresponding record in tableName . This way tableName can preserve its commonField uniqueness. How can i achieve this?
So, given the example tableNameTemp values ββin the table above, the table below shows how these values ββwill be displayed in the table tableName
ββββββββββββββββββββββββββ¦βββββββββ¦βββββββββ¦βββββββββ β Field4 AKA commonField β Field1 β Field2 β Field3 β β βββββββββββββββββββββββββ¬βββββββββ¬βββββββββ¬βββββββββ£ β SA12 β No β No β No β β βββββββββββββββββββββββββ¬βββββββββ¬βββββββββ¬βββββββββ£ β CY84 β Yes β Yes β Yes β β βββββββββββββββββββββββββ¬βββββββββ¬βββββββββ¬βββββββββ£ β EH09 β Yes β No β No β ββββββββββββββββββββββββββ©βββββββββ©βββββββββ©βββββββββ
Note that in any of the tables there is no primary key, and Field1 - Field4 are not the only fields in both tableName and tableNameTemp .