sandingdude
IS-IT--Management
I was wondering how to do 2 things:
1. Edit the font to make it larger on the popup window which displays my duplicates
2. Add a quick close button on the popup window which displays my duplicates
This is my VB Script the guys here were able to help me out with, it compares two tables to check for duplcaites by looking at certain fields. Here is the code:
Function import()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strsql As String
'SQL string for names that already exist in MAINDB
strsql = "SELECT IMPORTDB.FNAME AS FNAME1, IMPORTDB.LNAME AS LNAME1, " & _
"IMPORTDB.PHONE AS PHONE1, MAINDB.FNAME AS FNAME2, MAINDB.LNAME AS LNAME2, " & _
"MAINDB.PHONE AS PHONE2 " & _
"FROM IMPORTDB INNER JOIN MAINDB ON (IMPORTDB.LNAME = MAINDB.LNAME) WHERE " & _
"(IMPORTDB.FNAME = MAINDB.FNAME) OR (IMPORTDB.FNAME = Left(MAINDB.FNAME,1)) OR (Left(IMPORTDB.FNAME,1) = MAINDB.FNAME);"
Set db = Application.CurrentDb
Set rs = db.OpenRecordset(strsql)
rs.MoveLast
rs.MoveFirst
Do Until rs.EOF
If MsgBox("Name already exists:" & vbCrLf & vbCrLf & _
"IMPORTDB" & vbCrLf & _
rs.Fields("FNAME1").Value & " " & rs.Fields("LNAME1").Value & " " & _
rs.Fields("PHONE1").Value & vbCrLf & vbCrLf & _
"MAINDB" & vbCrLf & _
rs.Fields("FNAME2").Value & " " & rs.Fields("LNAME2").Value & " " & _
rs.Fields("PHONE2").Value & vbCrLf & vbCrLf & _
"Do you want to delete the record in IMPORTDB?", vbYesNo + vbQuestion, _
"Duplicate found") = vbYes Then
'Delete the duplicate record:
DoCmd.RunSQL "DELETE * FROM IMPORTDB WHERE IMPORTDB.FNAME = '" & _
rs.Fields("FNAME1").Value & "' AND IMPORTDB.LNAME = '" & _
rs.Fields("LNAME1").Value & "' AND IMPORTDB.PHONE = '" & _
rs.Fields("PHONE1").Value & "';"
rs.MoveNext
Else:
rs.MoveNext
End If
Loop
End Function
Thank you
1. Edit the font to make it larger on the popup window which displays my duplicates
2. Add a quick close button on the popup window which displays my duplicates
This is my VB Script the guys here were able to help me out with, it compares two tables to check for duplcaites by looking at certain fields. Here is the code:
Function import()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strsql As String
'SQL string for names that already exist in MAINDB
strsql = "SELECT IMPORTDB.FNAME AS FNAME1, IMPORTDB.LNAME AS LNAME1, " & _
"IMPORTDB.PHONE AS PHONE1, MAINDB.FNAME AS FNAME2, MAINDB.LNAME AS LNAME2, " & _
"MAINDB.PHONE AS PHONE2 " & _
"FROM IMPORTDB INNER JOIN MAINDB ON (IMPORTDB.LNAME = MAINDB.LNAME) WHERE " & _
"(IMPORTDB.FNAME = MAINDB.FNAME) OR (IMPORTDB.FNAME = Left(MAINDB.FNAME,1)) OR (Left(IMPORTDB.FNAME,1) = MAINDB.FNAME);"
Set db = Application.CurrentDb
Set rs = db.OpenRecordset(strsql)
rs.MoveLast
rs.MoveFirst
Do Until rs.EOF
If MsgBox("Name already exists:" & vbCrLf & vbCrLf & _
"IMPORTDB" & vbCrLf & _
rs.Fields("FNAME1").Value & " " & rs.Fields("LNAME1").Value & " " & _
rs.Fields("PHONE1").Value & vbCrLf & vbCrLf & _
"MAINDB" & vbCrLf & _
rs.Fields("FNAME2").Value & " " & rs.Fields("LNAME2").Value & " " & _
rs.Fields("PHONE2").Value & vbCrLf & vbCrLf & _
"Do you want to delete the record in IMPORTDB?", vbYesNo + vbQuestion, _
"Duplicate found") = vbYes Then
'Delete the duplicate record:
DoCmd.RunSQL "DELETE * FROM IMPORTDB WHERE IMPORTDB.FNAME = '" & _
rs.Fields("FNAME1").Value & "' AND IMPORTDB.LNAME = '" & _
rs.Fields("LNAME1").Value & "' AND IMPORTDB.PHONE = '" & _
rs.Fields("PHONE1").Value & "';"
rs.MoveNext
Else:
rs.MoveNext
End If
Loop
End Function
Thank you