Error when Form Loads (System Null Reference Exception)

  • Thread starter Thread starter Gary Simpson
  • Start date Start date
G

Gary Simpson

Guest
Hi Good People

I have a form called Money Totals. And what I am trying to achieve is when the form loads it shows running totals of a particular column, But I get an ( System Null Reference Exception, SQL was Nothing )

The code I have, I thought checked if record existed or not.

Private Sub ItemsPurchased()
'Sum Of Items Purchased =====================================
SQL.ExecQuery("SELECT Sum(AmountPaid) As AccountSum " &
"FROM ItemsPurchased ")
If SQL.RecordCount < 1 Then Exit Sub
TxtItemsPurchased.Text = "£0.00"

If SQL.RecordCount > 0 Then
TxtItemsPurchased.Text = SQL.SQLDT.Rows(0)("AccountSum").ToString()
TxtItemsPurchased.Text = FormatCurrency(TxtItemsPurchased.Text)
End If
End Sub

Another Code I tried ...

Private Sub ItemsPurchased()
'Sum Of Items Purchased =====================================
SQL.ExecQuery("SELECT Sum(AmountPaid) As AccountSum " &
"FROM ItemsPurchased ")
If SQL.RecordCount < 1 Then
TxtItemsPurchased.Text = "£0.00"

ElseIf SQL.RecordCount > 0 Then
TxtItemsPurchased.Text = SQL.SQLDT.Rows(0)("AccountSum").ToString()
TxtItemsPurchased.Text = FormatCurrency(TxtItemsPurchased.Text)
End If
End Sub

Can you good People show me or tell me where I am going wrong Please

Kind Regards

Gary



Gary Simpson

Continue reading...
 
Back
Top