Hi guys, I am building a program which has 5 forms, 1 mainmenuform with 4 buttons and each of them buttons have a form corrisponding to that button and this program is connected to my access database.

The problem I have is I've put all my code into my first button but it doesn't seem to work

This is the code for my button in the main menu.... once clicked it goes to my ExhibitorForm....Well it did before i put the code in on the ExhibitorForm now it throws up this message The 'Microsoft.ACE.OLEDB.12.0Data Source = Project.accdb' provider is not registered on the local machine. pointing at the con.open()

Public Class Mainmenu

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ExhibitorForm As New ExhibitorForm
        ExhibitorForm.ShowDialog()

    End Sub

and here is my code for the corrisponding form...

Public Class ExhibitorForm
    Dim inc As Integer
    Dim MaxRows As Integer
    Dim con As New OleDb.OleDbConnection
    Dim dbProvider As String
    Dim dbSource As String
    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim sql As String
    Dim cb As New OleDb.OleDbCommandBuilder(da)



    Private Sub ExhibitorForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12.0"
        dbSource = "Data Source = Project.accdb"

        con.ConnectionString = dbProvider & dbSource
        con.Open()

        sql = "SELECT * FROM tblExhibitorCompanies"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "Project")

        MaxRows = ds.Tables("Project").Rows.Count
        inc = -1
    End Sub

    Private Sub navigateRecords()
        TxtCompID.Text = ds.Tables("Project").Rows(inc).Item(0)
        TxtCompName.Text = ds.Tables("Project").Rows(inc).Item(1)
        TxtCompAddress.Text = ds.Tables("Project").Rows(inc).Item(2)
        TxtCompCity.Text = ds.Tables("Project").Rows(inc).Item(3)
        TxtCompPhoneNum.Text = ds.Tables("Project").Rows(inc).Item(4)
        TxtNumbStands.Text = ds.Tables("Project").Rows(inc).Item(5)
        TxtPriceStands.Text = ds.Tables("Project").Rows(inc).Item(6)

    End Sub


    Private Sub btnprevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprevious.Click
        If inc > 0 Then
            inc = inc - 1
            navigateRecords()
        ElseIf inc = -1 Then
            MsgBox("No Records Yet")

        ElseIf inc = 0 Then

            MsgBox("First Record")
        End If
    End Sub

    Private Sub btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnext.Click
        If inc <> MaxRows - 1 Then
            inc = inc + 1
        Else
            MsgBox("No More Rows")
        End If
    End Sub

    Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click

        Dim cb As New OleDb.OleDbCommandBuilder(da)

        ds.Tables("Project").Rows(inc).Item(0) = TxtCompID.Text
        ds.Tables("Project").Rows(inc).Item(1) = TxtCompName.Text
        ds.Tables("Project").Rows(inc).Item(2) = TxtCompAddress.Text
        ds.Tables("Project").Rows(inc).Item(3) = TxtCompCity.Text
        ds.Tables("Project").Rows(inc).Item(4) = TxtCompPhoneNum.Text
        ds.Tables("Project").Rows(inc).Item(5) = TxtNumbStands.Text
        ds.Tables("Project").Rows(inc).Item(6) = TxtPriceStands.Text



        da.Update(ds, "AddressBook")

        MsgBox("Data Updated")

        If inc <> -1 Then

        End If

        Dim dsNewRow As DataRow

        dsNewRow = ds.Tables("Project").NewRow()

        dsNewRow.Item("CompanyID") = TxtCompID.Text
        dsNewRow.Item("CompanyName") = TxtCompName.Text
        dsNewRow.Item("CompanyAddress") = TxtCompAddress.Text
        dsNewRow.Item("City") = TxtCompCity.Text
        dsNewRow.Item("TelephoneNumber") = TxtCompPhoneNum.Text
        dsNewRow.Item("NumberofStands") = TxtNumbStands.Text
        dsNewRow.Item("PriceofStands") = TxtPriceStands.Text



        ds.Tables("AddressBook").Rows.Add(dsNewRow)

        da.Update(ds, "AddressBook")

        MsgBox("New Record added to the Database")

        btnsave.Enabled = False
        btnadd.Enabled = True
        btnedit.Enabled = True
        btndelete.Enabled = True

    End Sub

    Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
        btnsave.Enabled = True
        btnadd.Enabled = False
        btnedit.Enabled = False
        btndelete.Enabled = False

        TxtCompID.Clear()
        TxtCompName.Clear()
        TxtCompAddress.Clear()
        TxtCompCity.Clear()
        TxtCompPhoneNum.Clear()
        TxtNumbStands.Clear()
        TxtPriceStands.Clear()

        With TxtCompID
            If Not .Text = "" Then '// check if not empty.
                Dim myCoolIDletters As String = "" '// new String to get all letters at beginning of ID.
                For i As Integer = 0 To .Text.Length - 1 '// loop until all letters located and added to String.
                    If Not IsNumeric(.Text(i)) Then myCoolIDletters &= .Text(i) Else Exit For
                Next
                '// set letters back and increase the #+1, with the format of 4#'s, as "0000".
                .Text = myCoolIDletters & (CInt(.Text.Substring(myCoolIDletters.Length)) + 1).ToString("0000")
            End If
        End With

    End Sub

    Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
        Dim cb As New OleDb.OleDbCommandBuilder(da)

        If MessageBox.Show("Please confirm you want to Delete this Record?", "Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.No Then
            MsgBox("Operation Canceled")
            Exit Sub

        End If
        ds.Tables("Project").Rows(inc).Delete()
        MaxRows = MaxRows - 1
        inc = 0
        navigateRecords()
        da.Update(ds, "Project")
    End Sub

    Private Sub btnhome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhome.Click
        Dim MainMenu As New Mainmenu
        Me.Hide()
        MainMenu.Close()
    End Sub
End Class

Any ideas?

Recommended Answers

All 5 Replies

will this solve my error?

Your error is telling you that you do not have the Ace Provider installed.

If you read what I directed you to, you would have seen that the engine installs this provider. Make sure you install the proper version (32/64- bit for your system and application.

looks to me like you're building your connection string wrong. Try adding a semi-colon between dbProvider and dbSource

Tntinmn: I didn't need to install that when I built my previous prog which was very similar to this as the only difference is that I have added a main menu form with 4 buttons to access the next form.

Tinstaafl: that is how it's written in my tutorial and it worked. So I think putting a semi colon in would work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.