Re: Populat a NewRecord from Text boxes Revisited
- From: "Keith Wilby" <here@xxxxxxxxx>
- Date: Mon, 17 Nov 2008 16:09:40 -0000
"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
.
- Follow-Ups:
- Re: Populat a NewRecord from Text boxes Revisited
- From: RICHARD BROMBERG
- Re: Populat a NewRecord from Text boxes Revisited
- From: RICHARD BROMBERG
- Re: Populat a NewRecord from Text boxes Revisited
- References:
- Populat a NewRecord from Text boxes Revisited
- From: RICHARD BROMBERG
- Populat a NewRecord from Text boxes Revisited
- Prev by Date: New Outlook Email with BCC field populated with Emails from Query
- Next by Date: Re: Populat a NewRecord from Text boxes Revisited
- Previous by thread: Populat a NewRecord from Text boxes Revisited
- Next by thread: Re: Populat a NewRecord from Text boxes Revisited
- Index(es):
Loading