Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare Tables by user selected relationships

Status
Not open for further replies.

ndltx5

Technical User
Jun 6, 2007
26
0
0
US
I'm trying to create an interface to import two Excel files and compare them for common entries. I've got the import part figured out i'm just having some trouble with the compare part. Here's what I got so far for the compare:

Code:
' set the variable for the first field to compare data with
    Table1List.SetFocus
    CompareField1 = Table1List.Text
' set the variable for the second field to compare
    Table2List.SetFocus
    CompareField2 = Table2List.Text

    Dim dbs As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim StrSQL As String
               
               
'set the current database
    Set dbs = CurrentDb
    
'check the database components and select matching data
    StrSQL = "SELECT Table1.['CompareField1'], Table2. ['CompareField2'] FROM Table1 LEFT JOIN Table2 ON ('*'+TABLE1.['CompareField1']+'*') Like ('*'+Table2.['CompareField2']+'*') WHERE Table1.['CompareField2'] is not null;"
    
    Set qdf = dbs.CreateQueryDef("Compared", StrSQL)


I can get it to work if i put in specific values in for CompareField1 and CompareField2, but how do i get it work when i want CompareField1 = Table1List where Table1List is a field chosen by the user to compare by.

Thanks for the help
 
N/M I fixed it by changing

Code:
'check the database components and select matching data
    StrSQL = "SELECT Table1.['CompareField1'], Table2. ['CompareField2'] FROM Table1 LEFT JOIN Table2 ON ('*'+TABLE1.['CompareField1']+'*') Like ('*'+Table2.['CompareField2']+'*') WHERE Table1.['CompareField2'] is not null;"

To

Code:
'check the database components and select matching data
     StrSQL = "SELECT Table1.[" & CompareField1 & "], Table2.[" & CompareField2 & "] FROM Table1 LEFT JOIN Table2 ON ('*'+TABLE1.[" & CompareField1 & "]+'*') Like ('*'+Table2.[" & CompareField2 & "]+'*') WHERE Table1.[" & CompareField1 & "] is not null;"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top