Here's a sample
Dim oCon As OdbcConnection
Dim oCmd As OdbcCommand
Dim ConnStr As String
Dim strSQL As String
ConnStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=<path to mdb file>"
oCon = New OdbcConnection(ConnStr)
oCon.Open()
oCmd = oCon.CreateCommand()
strSQL = "INSERT INTO <tablename> (<fieldname>) VALUES ('" & TextBox1.Text.Replace("'", "''") & "')"
oCmd.CommandText = strSQL
oCmd.ExecuteNonQuery()
oCon.Close()
Replace correct strings to connection string, table name and field name, and add some error handling code.
If you have trouble with connection string see
Connection strings for Access.
Reputation Points: 218
Solved Threads: 201
Veteran Poster
Offline 1,024 posts
since Aug 2008