In the root form, I have a control table that displays content from the form’s source table. The following macro works perfectly; it does what it’s supposed to do. Obviously, reloading the table returns the cursor to the first row of the grid.
.
Is there a way to reposition the cursor on the row corresponding to nStagingID? I’ve tried various methods like .absolute() and bookmark, but the only method that seemed to work was moving the cursor row by row, which is very tedious when there are many records. Is it possible to position the cursor directly on the nStagingID record?
.
Sub Resolve_Duplicate( oEvent As Object )
Dim oForm As Object : oForm = oEvent.Source.Model.Parent
Dim oConn As Object : oConn = oForm.ActiveConnection
Dim oStmt As Object : oStmt = oConn.createStatement()
' Read the columns of the selected line
Dim nStagingID As Long : nStagingID = oForm.Columns.getByName( "StagingID" ).Value
Dim nManualPersonID As Long : nManualPersonID = oForm.Columns.getByName( "ManualPersonID" ).Value
Dim sPersonName As String : sPersonName = oForm.Columns.getByName( "PersonName" ).Value
Dim sPersonURL As String : sPersonURL = oForm.Columns.getByName( "PersonURL" ).Value
If IsNull( nManualPersonID ) Then
ShowMsgBox "No duplicates to resolve for this line.", BtnOK, IconWarning, "Resolve Duplicate"
Exit Sub
End If
' Choice message
Dim sMsg As String
sMsg = "« " & sPersonName & " » already exists in the database with ID " & _
nManualPersonID & ". Do you want to associate this line with the existing person " & _
"or import this person as a new one?"
Dim vDGLResult As Variant
vDGLResult = ShowMsgBox( sMsg, BtnResolveDuplicate, IconQuestion, "Resolve Duplicate" )
Dim iUserChoice As Integer
iUserChoice = vDGLResult(0)
Select Case iUserChoice
Case 6
' Associate with the existing person
Dim oRS As Object
Dim sSelect As String
sSelect = _
"SELECT ""ProfessionID"", ""GenderID"", ""AliasTypeID"", ""CountryID"", " & _
"""AliasName"", ""BirthDate"", ""BirthYear"" " & _
"FROM ""PT_Person"" " & _
"WHERE ""PersonID"" = " & nManualPersonID
oRS = oStmt.executeQuery( sSelect )
If oRS.next() Then
Dim sExistingSQL As String
sExistingSQL = _
"UPDATE ""STG_CastingImport"" SET " & _
"""PersonID"" = " & nManualPersonID & ", " & _
"""ProfessionID"" = " & FormatSQLValue( oRS.getLong(1) ) & ", " & _
"""GenderID"" = " & FormatSQLValue( oRS.getLong(2) ) & ", " & _
"""AliasTypeID"" = " & FormatSQLValue( oRS.getLong(3) ) & ", " & _
"""CountryID"" = " & FormatSQLValue( oRS.getLong(4) ) & ", " & _
"""AliasName"" = " & FormatSQLString( oRS.getString(5) ) & ", " & _
"""BirthDate"" = " & FormatSQLDate( oRS.getDate(6) ) & ", " & _
"""BirthYear"" = " & FormatSQLValue( oRS.getInt(7) ) & ", " & _
"""MatchStatusID"" = 2, " & _
"""UpdateFilter"" = 1, " & _
"""ImportFilter"" = 0, " & _
"""ManualPersonID"" = NULL " & _
"WHERE ""StagingID"" = " & nStagingID
oStmt.executeUpdate( sExistingSQL )
End If
' -----------------------------------------------------------
' Update the URL in JT_PersonWebsite
' -----------------------------------------------------------
Dim sUpdateURL As String
sUpdateURL = _
"UPDATE ""JT_PersonWebsite"" SET ""URL"" = " & FormatSQLString( sPersonURL ) & _
" WHERE ""PersonID"" = " & nManualPersonID
oStmt.executeUpdate( sUpdateURL )
Case 7
' Import like a new person
Dim sNewSQL As String
sNewSQL = _
"UPDATE ""STG_CastingImport"" SET " & _
"""MatchStatusID"" = 1, " & _
"""UpdateFilter"" = 0, " & _
"""ImportFilter"" = 1 " & _
"WHERE ""StagingID"" = " & nStagingID
oStmt.executeUpdate( sNewSQL )
Case 2
' Cancel
Exit Sub
End Select
oForm.reload()
' If it possible, it is the place to do it.
End Sub