I have a problem when I need to remove the duplicate values in EstNo and EstWt when you have multiple ReleaseOp for example the 3 first lines below all showing ReleaseOp 1 should leave only the first record with the values 23 and 89. ReleaseAutoID is the Unique ID that identifies the record.
= the numbers in brackets below should be null.
ReqNo DeploymentYear ReleaseOp ReleaseAutoID EstNo EstWt
2 2013 1 1 23 89
2 2013 1 2 [23] [89]
2 2013 1 3 [23] [89]
2 2013 2 4 22 87
2 2013 2 5 [22] [87]
2 2013 3 6 24 90
My attempt as follow can’t seem to do what I want to do, it only checks if values are the same I am stuck on the condition and checks. I hope you can help and my problem makes sense.
Public Sub MakeTableObsFarmEst()
Dim rsExistData, rsSelectData, RsAboveAccessColumnLimit As ADODB.Recordset
Dim conn As ADODB.Connection
Dim cnnDB As ADODB.Connection
Dim strSelectData, strExistData, strRsAboveAccessColumnLimit As String
Dim strSQLInsert As String
Dim strUpdateSQL As String
Dim msg As String, Style As Integer, Title As String
Dim nl As String, ctl As Control, Source As String
Dim Response As VbMsgBoxResult
Dim lngNextID, lngEmploymentID, lngETTrainingID As Long
Dim lngGiveValue As String
'Dim i As Integer
Set rsExistData = New ADODB.Recordset
Set rsSelectData = New ADODB.Recordset
Set conn = New ADODB.Connection
Set cnnDB = CurrentProject.Connection
'conn.Open GstrConnection
Set RsAboveAccessColumnLimit = New ADODB.Recordset
nl = vbNewLine & vbNewLine
strSelectData = "Select * from qry_Caging_Farm_Obs_Est_Released_BFT_Layout"
rsSelectData.Open strSelectData, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
While Not rsSelectData.EOF
If rsExistData.State = adStateOpen Then
rsExistData.Close
Set rsExistData = Nothing
Set rsExistData = New ADODB.Recordset
End If
strExistData = "Select * from qry_Caging_Farm_Obs_Est_Released_BFT_Layout where [Release Op #]=" & rsSelectData.Fields("Release Op #") & " AND ReleaseAutoID=" & rsSelectData.Fields("ReleaseAutoID")
rsExistData.Open strExistData, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
While Not rsExistData.EOF
If rsSelectData.Fields("ReleaseAutoID") = rsExistData.Fields ("ReleaseAutoID") Then
'do nothing
Else
Debug.Print "Update Action to Clear Field"
End If
rsExistData.MoveNext
Wend
rsSelectData.MoveNext
Wend
If rsSelectData.State = adStateOpen Then
rsSelectData.Close
Set rsSelectData = Nothing
End If
If rsExistData.State = adStateOpen Then
rsExistData.Close
Set rsExistData = Nothing
End If
Exit Sub
= the numbers in brackets below should be null.
ReqNo DeploymentYear ReleaseOp ReleaseAutoID EstNo EstWt
2 2013 1 1 23 89
2 2013 1 2 [23] [89]
2 2013 1 3 [23] [89]
2 2013 2 4 22 87
2 2013 2 5 [22] [87]
2 2013 3 6 24 90
My attempt as follow can’t seem to do what I want to do, it only checks if values are the same I am stuck on the condition and checks. I hope you can help and my problem makes sense.
Public Sub MakeTableObsFarmEst()
Dim rsExistData, rsSelectData, RsAboveAccessColumnLimit As ADODB.Recordset
Dim conn As ADODB.Connection
Dim cnnDB As ADODB.Connection
Dim strSelectData, strExistData, strRsAboveAccessColumnLimit As String
Dim strSQLInsert As String
Dim strUpdateSQL As String
Dim msg As String, Style As Integer, Title As String
Dim nl As String, ctl As Control, Source As String
Dim Response As VbMsgBoxResult
Dim lngNextID, lngEmploymentID, lngETTrainingID As Long
Dim lngGiveValue As String
'Dim i As Integer
Set rsExistData = New ADODB.Recordset
Set rsSelectData = New ADODB.Recordset
Set conn = New ADODB.Connection
Set cnnDB = CurrentProject.Connection
'conn.Open GstrConnection
Set RsAboveAccessColumnLimit = New ADODB.Recordset
nl = vbNewLine & vbNewLine
strSelectData = "Select * from qry_Caging_Farm_Obs_Est_Released_BFT_Layout"
rsSelectData.Open strSelectData, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
While Not rsSelectData.EOF
If rsExistData.State = adStateOpen Then
rsExistData.Close
Set rsExistData = Nothing
Set rsExistData = New ADODB.Recordset
End If
strExistData = "Select * from qry_Caging_Farm_Obs_Est_Released_BFT_Layout where [Release Op #]=" & rsSelectData.Fields("Release Op #") & " AND ReleaseAutoID=" & rsSelectData.Fields("ReleaseAutoID")
rsExistData.Open strExistData, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
While Not rsExistData.EOF
If rsSelectData.Fields("ReleaseAutoID") = rsExistData.Fields ("ReleaseAutoID") Then
'do nothing
Else
Debug.Print "Update Action to Clear Field"
End If
rsExistData.MoveNext
Wend
rsSelectData.MoveNext
Wend
If rsSelectData.State = adStateOpen Then
rsSelectData.Close
Set rsSelectData = Nothing
End If
If rsExistData.State = adStateOpen Then
rsExistData.Close
Set rsExistData = Nothing
End If
Exit Sub