I am trying in VBA to reference a table for data to compare to another table. I think the issue is that I am only checking 1 row in the lookup table. How do I get it to do a lookup until found, or until end of file? If no data then [NN] = 0 or null.
I am getting confused on the Do While Loop I guess.
Thanks
Code:
Private Sub SINCTest_Click()
Dim Uname As Variant
Dim I As Integer, Z As Integer
Dim NewWave As String, BDEs As String, Base As String, DIV As String, NN As String
Set rU = CurrentDb.OpenRecordset("NBOI") ' Main table
Set rN = CurrentDb.OpenRecordset("New_Net_ID") ' Lookup table
V = " VHF"
BDEs = "2BCT1ID"
DIV = "1ID "
If rU.BOF And rU.EOF Then
rU.Close
Else
rU.MoveLast
rU.MoveFirst
Do While Not rU.EOF
rU.Edit
If rU![BN (Owning)] <> rU![BN (Operating)] Then
BN = rU![BN (Operating)]
ElseIf rU![BN (Owning)] = rU![BN (Operating)] Then
BN = rU![BN (Owning)]
Else: BN = ""
End If
Uname = BN
Select Case BN
Case Is = "BDE"
Base = BDEs
Z = 1
Case Is = "DIV"
Base = DIV
Z = 0
Case Else
Base = ""
End Select
For I = 1 To 6
If rU("SINCGARS " & I) = rN("NBOI_NET") Then
NN = rN("NETID")
End If
If rU("SINCGARS " & I) = "METT" Then
rU("SINC" & I) = "12500-METT-T" & V
ElseIf rU("SINCGARS " & I) Like "Div*" Then
rU("SINC" & I) = NN & "-" & DIV & Right(rU("SINCGARS " & I), 3) & V
ElseIf rU("SINCGARS " & I) Like "Bde*" Then
NewWave = Base & Right(rU("SINCGARS " & I), (Len(rU("SINCGARS " & I)) - 3))
rU("SINC" & I) = NN & "-" & NewWave & V
ElseIf IsNull(rU("SINCGARS " & I)) Or rU("SINCGARS " & I) = "" Then
rU("SINC" & I) = ""
End If
End If
Next I
rU.Update
rU.MoveNext
Loop
End If
rU.Close
Set rU = Nothing
Set rN = Nothing
End Sub