Insert code...

Myriad_Rocker

Questioning Reality
Local time
Today, 10:09
Joined
Mar 26, 2004
Messages
166
I want to insert a record into a table that's value is in a text box on my form. When I click the "Insert" button, I want that value to go to said field in the table...

Private Sub btn_insert_Click()
On Error GoTo Err_btn_insert_Click


DoCmd.GoToRecord , , acNewRec

Exit_btn_insert_Click:
Exit Sub

Err_btn_insert_Click:
MsgBox Err.Description
Resume Exit_btn_insert_Click

End Sub
 
By the way, here's my form.
 

Attachments

  • untitled.GIF
    untitled.GIF
    21.9 KB · Views: 134
you have an unbound field. You'll need to make the buttons' event run an insert query and take the value of the field as its' parameter.

Private Sub btn_insert_Click()
On Error GoTo Err_btn_insert_Click

Dim SQL as String Conn as connection
Set conn=currentproject.connection

SQL="INSERT INTO TABLENAME (fieldname) values ('" & me.textboxname &"') "
Conn.execute(SQL)
conn.close
set conn=nothing

Exit_btn_insert_Click:
Exit Sub

Err_btn_insert_Click:
MsgBox Err.Description
Resume Exit_btn_insert_Click

End Sub
 
See below for what I have. Am I missing a reference of some kind?

Private Sub btn_insert_Click()
On Error GoTo Err_btn_insert_Click

Dim SQL as String Conn as connection
Set conn = CurrentProject.Connection

SQL = "INSERT INTO Emplids (Empl) values ('" & Me.txtSearchBox & "') "
conn.Execute (SQL)
conn.Close
Set conn = Nothing

Exit_btn_insert_Click:
Exit Sub

Err_btn_insert_Click:
MsgBox Err.Description
Resume Exit_btn_insert_Click
End Sub
 

Users who are viewing this thread

Back
Top Bottom