Re: Populat a NewRecord from Text boxes Revisited



Thank you Keith.

I did not in fact use a field name of "NAME" in the table.
I only used "NAME" in my posting, the table actually uses "FirstName" .





When I used the field name
"Keith Wilby" <here@xxxxxxxxx> wrote in message
news:492192f2$1_1@xxxxxxxxxxxxxxxxxxxxxxxxx
"RICHARD BROMBERG" <dickbrom@xxxxxxxxxxxxxxxx> wrote in message
news:XcgUk.31787$_Y1.6164@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


Please bear in mind that I am a newbie.
I am posting this question a second time because the responses to my
earlier post were a little wide of the mark.

People can only give as good a respose as the the original information
allows. If you consider them "wide of the mark" then I would suggest that
the OP was unclear.

So, here goes:

I am using Access 2000 and I would like to make a data entry form
(frmDataEntry) with a two text boxes.

The table (tblPeople) has fields Name and Age. Both are character fields.
The Form has two text boxes (txtName and txtAge)

On the form I created a command button (cmdAddPerson)
I used a command button (the command button wizard, record operations,Add
New Record) and it generates the code snippet below.
My understanding is that this creates a new unpopulated record in the
table.

Your understanding is correct but it isn't a sh!te of use to you.


Now I want to populate the new record from the txtName and txtAge text
boxes.

I think I have to add some code in the area I marked with question marks
in
the snippet, something like:
XXXXXXX = Me.txtName
YYYYYYYY = Me.txtAge.

Can I replace the XXXXXXX and YYYYYYY with a reference to the newly
created record?


Don't use the DoCmd method, you will need some code. Discard all of the
code and replace it with this:

Private Sub commandAddRecord_Click()

Dim db As DAO.Database, rs As DAO.Recordset, strSQL As String
Set db = CurrentDb

strSQL = Select * from tblPeople"
Set rs = db.OpenRecordset(strSQL)

With rs
.AddNew
![fldName] = Me.txtName
![Age] = Me.txtAge
.Update
End With

rs.Close
Set rs = Nothing
Set db = Nothing

Me.Requery

End Sub

The requery line will take you to the beginning of the recordset so you'll
probably need a method of going to the new record (GoTo Last might work).
I have assumed that you have heeded previous advice to rename the Name
field (fldName in my example).

Keith.
www.keithwilby.co.uk


.


Loading