Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert values into table from text box 1

Status
Not open for further replies.

instructorTek

Instructor
Jun 5, 2006
61
0
0
Hi all, I have a form in which the user fills out text boxes and clicks a button and all the information is committed to a table. Presently, every time I click the button the information is entered in the first record of the table only, I can't seem to get the information into new records. What am I missing here? The code is as follows:
The name of the table is tbl1 which contains the fields entry1 and entry2. The form text boxes are called txt1 and txt2.

Option Compare Database
Dim sql As String
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset

Private Sub cmd1_Click()
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset

rst.Open "tbl1", cnn, adOpenDynamic, adLockOptimistic
With rst
!entry1 = txt1.Value
!entry2 = txt2.Value
.AddNew
End With

rst.MoveNext
rst.Close

End Sub
 
rst.Open "tbl1", cnn, adOpenDynamic, adLockOptimistic
With rst
[!].AddNew[/!]
!entry1 = txt1.Value
!entry2 = txt2.Value
End With

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top