Im using Microsoft Visual Studio 2010
Microsoft Acess 2010

This is for practice
Lets See First off i was able to get to insert records(Code Below)
Now im trying to get the program to prompt a message when the id or field exists on the key down event and not enter it if it exists and if it doesnt exist im guessing i could use my already existing code to insert it
Any Examples?

Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
        If e.KeyCode = Keys.Enter Then
            Button3.Enabled = True
        End If

        If e.KeyCode = Keys.Enter Then
            e.SuppressKeyPress = True
            CecilSpeak.Text = "Hello," + TextBox2.Text + ""

            If MessageBox.Show("Are you sure this is your name?", "Save", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
                CecilSpeak.Text = "Hello," + TextBox2.Text + ""
                TextBox2.Enabled = False
                Dim con As New OleDbConnection
                Dim dbProvider As String
                Dim dbSource As String
                Dim ds As New DataSet
                Dim da As OleDb.OleDbDataAdapter
                Dim sql As String

                dbProvider = "Provider=Microsoft.Jet.OLEDB.4.0;"
                dbSource = "Data Source = Resources\Database4.mdb"

                con.ConnectionString = dbProvider & dbSource

                MsgBox("Database is now open")

                sql = "Select * FROM Namess"
                da = New OleDb.OleDbDataAdapter(sql, con)
                da.Fill(ds, "Namess")
                If inc <> -1 Then

                    Dim cb As New OleDb.OleDbCommandBuilder(da)
                    Dim dsNewRow As DataRow
                    da.Fill(ds, "Namess")

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

                    dsNewRow.Item("Field1") = TextBox2.Text


                    da.Update(ds, "Namess")

                    MsgBox("New Record added to the Database")

                    MsgBox("Database is now Closed")
                End If
                Button3.Enabled = False
                CecilSpeak.Text = "Not Your Name?"
            End If

        End If

    End Sub

Recommended Answers

All 2 Replies

If inc <> -1 Then

I can't find the declaration of inc

Oh its in the declarations section

Public Class Form1
    Private inc As Integer
Be a part of the DaniWeb community

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