tags:

views:

11

answers:

0

I Have a problem with this VBA Code; It works fine when the Debtor Currently has an outstanding Balance, but when their Balance is "" it throws an error and Highlights;

    Balance = CSng(txtBalance.Value)

Any help would be appreciated, I assume it would require something like;

    If txtBalance.Value = "" Then
        Worksheets("Debtor_List").Range("B" & DebtorRow).Value = Amount
        Exit Sub
    End If

Private Sub cmdBuy_Purchase_Click()

    Debtor = Purchase_Select_Debtor.Value
    Amount = CSng(txtPrice.Value)
    Balance = CSng(txtBalance.Value)

    If Debtor = "" Then
        MsgBox "Select Debtor"
        Exit Sub
    End If

    DebtorRow = 1
    Do
        TempDebtor = Worksheets("Debtor_list").Range("A" & DebtorRow).Value
        If TempDebtor = Debtor Then
            DebtorBalance = CSng(Worksheets("Debtor_List").Range("B" & DebtorRow).Value)
            Exit Do
        End If
        DebtorRow = DebtorRow + 1
    Loop Until TempDebtor = ""

    If TempDebtor = "" Then
        MsgBox "Debtor not found"
        Exit Sub
    End If

    Worksheets("Debtor_List").Range("B" & DebtorRow).Value = DebtorBalance - Amount

    Balance = Application.VLookup(Purchase_Select_Debtor.Value, Sheets("Debtor_list").Range("A2:B13"), 2, 0)

    MsgBox "You have just Purchased " & Purchase_Select_Quantity.Value & " For $" & Amount & vbCrLf & "Your Account Balance is now: " & Balance

    Unload FrmPurchase

End Sub