|
|
Title | Use DAO to add records to a database |
Keywords | database, DAO, add record, insert record |
Categories | Database |
|
|
Use the Database object's Execute method to execute an INSERT SQL statement.
|
|
' Add a record.
Private Sub cmdAdd_Click()
Dim query As String
' Create an INSERT action query.
query = "INSERT INTO People VALUES("
query = query & "'" & txtLastName.Text & "', "
query = query & "'" & txtFirstName.Text & "', "
query = query & "'" & txtId.Text & "'"
query = query & ")"
' Execute the query.
On Error GoTo NotInserted
db.Execute query
MsgBox "Ok"
Exit Sub
NotInserted:
MsgBox "Error" & Str$(Err.Number) & _
" inserting record." & vbCrLf & _
Err.Description
End Sub
|
|
|
|
|
|