I have the following code and it is not passing through the Next statement:
Private Function IsItemAlreadyAdded() As Boolean
Dim drMyRow As DataRow
With Me
For Each drMyRow In .dsTOB.Tables("TempOB").Rows
If .acctNumber = drMyRow("AccountNo") Then
Return True
Else
Return False
End If
Next
End With
End Function
I call the function in the following code to make sure that an item added
already in the temporary table is not added again:
Private Sub AddToTempOpenBalance()
With Me
Try
If .IsItemAlreadyAdded = True Then
Dim msg1 As New MessageDialogForm
msg1.DialogCaption = "Data Entry"
msg1.DialogMessage = "Please the account is already added"
msg1.ShowDialog()
.txtOpenBalance.Focus()
Else
If .IsAllFieldsNotComplete = True Then
Dim msg As New MessageDialogForm
msg.DialogCaption = "Data Entry"
msg.DialogMessage = "Please complete all fields and
continue"
msg.ShowDialog()
.txtOpenBalance.Focus()
Else
Dim pcRow As DataRow = .dtTempOB.NewRow()
pcRow("Date") = .dtpDate.Value
If .rbOtherAccounts.Checked = True Then
pcRow("AccountNo") = .otherAcctNo
End If
If .rbBankAccounts.Checked = True Then
pcRow("AccountNo") = .bankAcctNo
End If
If .chkCredit.CheckState = CheckState.Checked Then
pcRow("CreditBalanceBF") = .txtOpenBalance.Text
End If
If .chkDebit.CheckState = CheckState.Checked Then
pcRow("DebitBalanceBF") = .txtOpenBalance.Text
End If
Me.dtTempOB.Rows.Add(pcRow)
End If
End If
Catch ex As Exception
Dim msg As New MessageDialogForm
msg.DialogCaption = "Add Record"
msg.DialogMessage = "An error of type " &
ex.GetType().ToString() & _
" occured while adding record to temporary table."
msg.ShowDialog()
End Try
End With
End Sub
The "For Each Next" code is not able to loop through the temporary table to
compare the acctNumber with account numbers whether it is already in the
temporary table.
The acctNumber variable is the current account number selected by the user
which is being compared with the various account numbers in the temporary
table.