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:
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
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