[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Check for no records or only one record in Access DB

Posted on 2004-10-19
2
Medium Priority
?
203 Views
Last Modified: 2010-04-24
Hello,

I am working on a project that takes input data and saves it to a database in Access using ADO.
I have the program working correctly until I take out the records and check for no records. It crashes on the totals. Please see below



Dim pintRecords As Integer
        Dim pbndTemp As Binding

        lblDisplay.Visible = True
        lblAddMode.Visible = False
        lblEditMode.Visible = False
        pintRecords = oledbCustomers1.Fill(DsCustomers1)
        btnPrevious.Enabled = False

        ' Populate the DataSet with records using the DataAdapter. This DataAdapter was
        ' configured using the Wizard supplied by the OleDbDataAdapter control.

        ' Set up the bindings for each control instance. For each control instance, create
        ' a Binding object. Specify the property to bind (Text), the DataSet, and the
        ' navigation path to the field. Scond, add the binding the the control instance's
        ' DataBindings collection.

       
           

            pbndTemp = New Binding("Text", DsCustomers1, "tblCustomers.fldCustomerID")
            txtCustID.DataBindings.Add(pbndTemp)

            pbndTemp = New Binding("Text", DsCustomers1, "tblCustomers.fldFirstName")
            txtFirst.DataBindings.Add(pbndTemp)

            pbndTemp = New Binding("Text", DsCustomers1, "tblCustomers.fldLastName")
            txtLast.DataBindings.Add(pbndTemp)

            pbndTemp = New Binding("Text", DsCustomers1, "tblCustomers.fldAddress")
            txtAddress.DataBindings.Add(pbndTemp)

            pbndTemp = New Binding("Text", DsCustomers1, "tblCustomers.fldCity")
            txtCity.DataBindings.Add(pbndTemp)

            pbndTemp = New Binding("Text", DsCustomers1, "tblCustomers.fldState")
            txtState.DataBindings.Add(pbndTemp)

            pbndTemp = New Binding("Text", DsCustomers1, "tblCustomers.fldZipCode")
            txtZip.DataBindings.Add(pbndTemp)

            pbndTemp = New Binding("Text", DsCustomers1, "tblCustomers.fldAnnualSales")
            txtAnnSales.DataBindings.Add(pbndTemp)

            pbndTemp = New Binding("Text", DsCustomers1, "tblCustomers.fldBalanceDue")
            txtBalDue.DataBindings.Add(pbndTemp)

            pbndTemp = New Binding("Text", DsCustomers1, "tblCustomers.fldCreditLimit")
        txtCredit.DataBindings.Add(pbndTemp)
        Call EditState(cblnNotEditing)
        Call Totals()

        If txtCustID.Text = "" Then
            MessageBox.Show("There are no records currently in this database")
            grpNavigate.Hide()
            lblOverLimit.Visible = False
            tmrInvalid.Stop()
            btnAdd.Enabled = False
            btnEdit.Enabled = True
            btnsave.Enabled = True
            btnCancel.Enabled = False
            btnDelete.Enabled = False

            Exit Sub
        End If
        End Sub

****For the totals I have the following:

Private Sub Totals()
        Dim mdblmonthSal As Double
        Dim mdblannualSales As Double
        Dim mdblCreditLimit As Double
        Dim mdblBalDue As Double
        Dim mdblAvailBal As Double


        mdblannualSales = ToDouble(txtAnnSales.Text)  ***************CRASHES ON THIS LINE
        mdblmonthSal = mdblannualSales / 12
        txtMonth.Text = mdblmonthSal.ToString("###,###.##")

        mdblCreditLimit = ToDouble(txtCredit.Text)
        mdblBalDue = ToDouble(txtBalDue.Text)

        mdblAvailBal = mdblCreditLimit - mdblBalDue
        txtBalAvail.Text = mdblAvailBal.ToString("###,###.##")

        If mdblCreditLimit = mdblBalDue Then
            txtBalAvail.Text = "Zero Balance"
        End If
        Call Overlimit()
    End Sub

*********The Form Load is looking at the temp holding variable (mdblCreditLimit)  and telling me the input text is incorrect. Should be ToString.
Also how would I check for only one record in the Access DB.

Thanks for your help.
0
Comment
Question by:itcopt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Expert Comment

by:planocz
ID: 12351067
You could do something like this....

Dim pintRecords As Integer
        Dim pbndTemp As Binding

        lblDisplay.Visible = True
        lblAddMode.Visible = False
        lblEditMode.Visible = False
        pintRecords = oledbCustomers1.Fill(DsCustomers1)
        btnPrevious.Enabled = False

        if DsCustomers1.Tables(0).Rows.Count <= 1 then
              messagebox("I have only one or less records")
              exit sub
       end if
0
 
LVL 4

Accepted Solution

by:
eozz_2000 earned 500 total points
ID: 12351854
I would change the code above with the name of the table, becaouse I wouldn't know if the table with the index 0 is the table that itcopt wants to check:

Select Case DsCustomers1.Tables("Table_Name").Rows.Count
  case 0:
    msgbox("The table is empty")
  case 1:
    msgbox("You have only 1 record")
  case Else:
    'The execution will be here if you have 2 or more records
End Select
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question