- Local time
- Today, 06:33
- Joined
- Feb 28, 2001
- Messages
- 29,898
Always glad to help.
SELECT tbltwodemo.uniqueid,
tbltwodemo.userid,
tbltwodemo.firstname,
tbltwodemo.lastname,
tbltwodemo.[full name],
tbltwodemo.email,
tbltwodemo.phonenumber,
tbltwodemo.street,
tbltwodemo.city,
tbltwodemo.state,
tbltwodemo.country,
tbltwodemo.zipcode,
tbltwodemo.domain,
tbltwodemo.username,
tbltwodemo.ip_address,
tbltwodemo.[created at],
tbltwodemo.parkingspot
FROM tbltwodemo
WHERE ( ( ( tbltwodemo.userid ) = [_userid] )
AND ( ( tbltwodemo.firstname ) = [_firstname] )
AND ( ( tbltwodemo.lastname ) = [_lastname] )
AND ( ( tbltwodemo.[full name] ) = [_full name] )
AND ( ( tbltwodemo.email ) = [_email] )
AND ( ( tbltwodemo.phonenumber ) = [_phonenumber] )
AND ( ( tbltwodemo.street ) = [_street] )
AND ( ( tbltwodemo.city ) = [_city] )
AND ( ( tbltwodemo.state ) = [_state] )
AND ( ( tbltwodemo.country ) = [_country] )
AND ( ( tbltwodemo.zipcode ) = [_zipcode] )
AND ( ( tbltwodemo.domain ) = [_domain] )
AND ( ( tbltwodemo.username ) = [_username] )
AND ( ( tbltwodemo.ip_address ) = [_ip_address] )
AND ( ( tbltwodemo.[created at] ) = [_created at] )
AND ( ( tbltwodemo.parkingspot ) = [_parkingspot] ) );
Public Sub MatchFields()
Dim rsSearch As DAO.Recordset
Dim strSql As String
Dim db As DAO.Database
Set db = CurrentDb
Set rsSearch = db.OpenRecordset("Select * from tblOneDemo")
Do While Not rsSearch.EOF
IsMatch rsSearch ' this is a function so you can return the value if it is a match
rsSearch.MoveNext
'Exit Do
Loop
End Sub
Public Function IsMatch(rsSearch As DAO.Recordset) As Boolean
Dim rsFind As DAO.Recordset
Dim strSql As String
Dim qdf As QueryDef
Dim db As DAO.Database
Dim prms As Parameters
Dim prm As DAO.Parameter
Dim fld As DAO.Field
Dim prmField As String
Dim newSql As String
Dim OldSql As String
Set db = CurrentDb
Set qdf = db.QueryDefs("qryIsMatch")
Set prms = qdf.Parameters
newSql = qdf.SQL
OldSql = qdf.SQL
'replace the null parameters with Is null
For Each prm In prms
'Unfortunately need to run this twice
'all values lost after resetting qdf.sql
prmField = Replace(prm.Name, "[", "")
prmField = Replace(prmField, "]", "")
prmField = Mid(prmField, 2)
prm.Value = rsSearch.Fields(prmField).Value
'change the sql string
If IsNull(prm.Value) Then
newSql = Replace(newSql, "=" & prm.Name, "is Null")
End If
Next prm
qdf.SQL = newSql
For Each prm In prms
prmField = Replace(prm.Name, "[", "")
prmField = Replace(prmField, "]", "")
prmField = Mid(prmField, 2)
prm.Value = rsSearch.Fields(prmField).Value
Next prm
Set db = CurrentDb
'Debug.Print qdf.SQL
'For Each prm In prms
' Debug.Print prm.Name & prm.Value
'Next prm
Set rsFind = qdf.OpenRecordset
If Not rsFind.EOF And Not rsFind.BOF Then
rsFind.MoveLast
InsertMatch rsSearch!uniqueID, rsFind!uniqueID
End If
qdf.SQL = OldSql
End Function
Public Sub InsertMatch(table1ID As Long, table2ID As Long)
Dim strSql As String
strSql = "Insert into tblMatches (IDTableOne, IDTableTwo) values (" & table1ID & ", " & table2ID & ")"
CurrentDb.Execute strSql
End Sub
[_UserID] 0
[_LastName] Emmerich
[_Full Name] Keon Wiegand
[_Email] [email]Merritt@emily.us[/email]
[_PhoneNumber](568)232-8693 x581
[_Street] 655 Herman Radial
[_City] East Thurman
[_State] Montana
[_Country] Fiji
[_zipCode] 14539-1448
[_Domain] annie.me
[_UserName] Emie_King
[_IP_Address] 203.209.94.235
[_Created At] 4/3/2019 6:25:14 PM
[_ParkingSpot]986
AND ( ( tbltwodemo.firstname ) = [_firstname] )
AND ( ( tbltwodemo.lastname ) = "Emmerich" )
AND ( ( tbltwodemo.[full name] ) = "Keon Wiegan" )
AND ( ( tbltwodemo.email ) = [_email] )
AND ( ( tbltwodemo.phonenumber ) = [_phonenumber] )
AND ( ( tbltwodemo.street ) = [_street] )
AND ( ( tbltwodemo.city ) = [_city] )
AND ( ( tbltwodemo.state ) = [_state] )
AND ( ( tbltwodemo.country ) = [_country] )
AND ( ( tbltwodemo.zipcode ) = [_zipcode] )
AND ( ( tbltwodemo.domain ) = [_domain] )
AND ( ( tbltwodemo.username ) = [_username] )
AND ( ( tbltwodemo.ip_address ) = [_ip_address] )
AND ( ( tbltwodemo.[created at] ) = [_created at] )
AND ( ( tbltwodemo.parkingspot ) = [_parkingspot]
AND ( ( tbltwodemo.firstname ) is Null )
AND ( ( tbltwodemo.lastname ) is Null )
AND ( ( tbltwodemo.[full name] ) = [_Full Name] )
AND ( ( tbltwodemo.email ) = [_email] )
until you run it on real data you never know what you forget to think about.
Can you point out which records? The main point of this code was to try to find records with the equivalent null records. If the code it is failing do that then not much has been gained from other approaches. I thought from my test it was matching like nulls.Just one important issue however.
The 3 records with nulls in the same field in both tables were marked as MATCHED
Can you point out which records? The main point of this code was to try to find records with the equivalent null records. If the code it is failing do that then not much has been gained from other approaches. I thought from my test it was matching like nulls.
What is interesting for me is that code in VBA is faster than joins.
Looping one record by record is faster than joins, why is that?
I'm now thinking about logging fields with differences as the test progresses & displaying those for information ....
Have you already looked into doing this.
If strNullMatch = "" Then
strNullMatch = prmField
Else
strNullMatch = strNullMatch & "; " & prmField
End If