Populat a NewRecord from Text boxes Revisited | | |
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.
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.
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?
Help would be greatly appreciated.
******************** snippet ***********
Private Sub commandAddRecord_Click()
On Error GoTo Err_commandAddRecord_Click
DoCmd.GoToRecord , , acNewRec
'
' Move information from textboxes to the new record
'
' ????????????????????????????????????
' ????????????????????????????????????
'
Exit_commandAddRecord_Click:
Exit Sub
Err_commandAddRecord_Click:
MsgBox Err.Description
Resume Exit_commandAddRecord_Click
End Sub
******************** snippet *********** | | | | re: Populat a NewRecord from Text boxes Revisited
"RICHARD BROMBERG" <dickbrom@worldnet.att.netwrote in message
news:XcgUk.31787$_Y1.6164@bgtnsc05-news.ops.worldnet.att.net... Quote:
>
>
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. Quote:
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. Quote:
>
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 | | | | 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@there.comwrote in message
news:492192f2$1_1@glkas0286.greenlnk.net... Quote:
"RICHARD BROMBERG" <dickbrom@worldnet.att.netwrote in message
news:XcgUk.31787$_Y1.6164@bgtnsc05-news.ops.worldnet.att.net... Quote:
>>
>>
>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.
> Quote:
>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.
> Quote:
>>
>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 | | | | re: Populat a NewRecord from Text boxes Revisited
Keith
Getting closer.
The Dim statement Dim db As DAO.Database, rs As DAO.Recordset, strSQL As
String does not compile so I split the dim statement up into three seperate
Dim statements as follows:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
The first two dim statements cause a compiler error error User type not
defined .
I looked through the add in manager but found nothing there at all.
Where do I get the definitions?
Again, thanks
"Keith Wilby" <here@there.comwrote in message
news:492192f2$1_1@glkas0286.greenlnk.net... Quote:
"RICHARD BROMBERG" <dickbrom@worldnet.att.netwrote in message
news:XcgUk.31787$_Y1.6164@bgtnsc05-news.ops.worldnet.att.net... Quote:
>>
>>
>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.
> Quote:
>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.
> Quote:
>>
>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 | | | | re: Populat a NewRecord from Text boxes Revisited
In some versions of Access, the Data Access Objects DLLs were not, by
default, included in the References. Go to a module window, and on the menu
Tools | References, and check the entry for the DAO library... I usually
move it up above the ADO library, just in case I forget.
However, I am wondering why you do not just bind your form to the Table or a
Query on the Table, and place First Name and Age controls on the Form with
Control Source of the corresponding Fields. If you only want the form used
to add new records, you can set the "Data Entry" property of the Forms Data
properties; but my users have never seemed to have any problem using the
same form for editing existing records and using the navigation buttons to
go to a new Record to add.
If the target users of an application were really raw novice casual users, I
might add Command Buttons to the Form to switch the properties, so that
normally they could just view, but had to click a button to Edit an existing
Record, or click a different button to add a new Record.
Access makes data entry and editing so trivially simple with bound forms
that I continue to be amazed, sixteen years after Access was first released,
how many people think they have to use unbound forms and code to do these
simple tasks -- when they are re-implementing built-in features of the
product.
Larry Linson
Microsoft Office Access MVP
"RICHARD BROMBERG" <dickbrom@worldnet.att.netwrote in message
news:xpkUk.32068$_Y1.6931@bgtnsc05-news.ops.worldnet.att.net... Quote:
Keith
>
Getting closer.
>
The Dim statement Dim db As DAO.Database, rs As DAO.Recordset, strSQL As
String does not compile so I split the dim statement up into three
seperate Dim statements as follows:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
>
The first two dim statements cause a compiler error error User type not
defined .
I looked through the add in manager but found nothing there at all.
>
Where do I get the definitions?
>
Again, thanks
>
>
"Keith Wilby" <here@there.comwrote in message
news:492192f2$1_1@glkas0286.greenlnk.net... Quote:
>"RICHARD BROMBERG" <dickbrom@worldnet.att.netwrote in message
>news:XcgUk.31787$_Y1.6164@bgtnsc05-news.ops.worldnet.att.net... Quote:
>>>
>>>
>>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.
>> Quote:
>>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.
>> Quote:
>>>
>>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 >
>
| | | | re: Populat a NewRecord from Text boxes Revisited
On Nov 17, 10:37*am, "RICHARD BROMBERG" <dickb...@worldnet.att.net>
wrote: Quote:
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.
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.
>
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?
>
Help would be greatly appreciated.
>
******************** snippet ***********
Private Sub commandAddRecord_Click()
>
On Error GoTo Err_commandAddRecord_Click
* * DoCmd.GoToRecord , , acNewRec
'
' * * *Move information from textboxes to the new record
'
' * *????????????????????????????????????
' * *????????????????????????????????????
'
Exit_commandAddRecord_Click:
* * Exit Sub
>
Err_commandAddRecord_Click:
* * MsgBox Err.Description
* * Resume Exit_commandAddRecord_Click
>
End Sub
>
******************** snippet ***********
I think everyone is assuming you know how to simply build a form that
is bound to the table and that what you're doing is for educational
purposes.
Is that the case? Do you know how to use the form wizard? | | | | re: Populat a NewRecord from Text boxes Revisited
Larry
Thanks
I am just learning and don't really have enough experience of insight to
determine the easiest or simplest way of doing things.
After I get the present program to work, I am going back and try the way
you suggest.
Once again,
many thanks
I guess that comes with a little more experience.
"Larry Linson" <bouncer@localhost.notwrote in message
news:ERkUk.1144$4g5.387@nwrddc01.gnilink.net... Quote:
In some versions of Access, the Data Access Objects DLLs were not, by
default, included in the References. Go to a module window, and on the
menu Tools | References, and check the entry for the DAO library... I
usually move it up above the ADO library, just in case I forget.
>
However, I am wondering why you do not just bind your form to the Table or
a Query on the Table, and place First Name and Age controls on the Form
with Control Source of the corresponding Fields. If you only want the
form used to add new records, you can set the "Data Entry" property of the
Forms Data properties; but my users have never seemed to have any problem
using the same form for editing existing records and using the navigation
buttons to go to a new Record to add.
>
If the target users of an application were really raw novice casual users,
I might add Command Buttons to the Form to switch the properties, so that
normally they could just view, but had to click a button to Edit an
existing Record, or click a different button to add a new Record.
>
Access makes data entry and editing so trivially simple with bound forms
that I continue to be amazed, sixteen years after Access was first
released, how many people think they have to use unbound forms and code to
do these simple tasks -- when they are re-implementing built-in features
of the product.
>
Larry Linson
Microsoft Office Access MVP
>
>
"RICHARD BROMBERG" <dickbrom@worldnet.att.netwrote in message
news:xpkUk.32068$_Y1.6931@bgtnsc05-news.ops.worldnet.att.net... Quote:
>Keith
>>
>Getting closer.
>>
>The Dim statement Dim db As DAO.Database, rs As DAO.Recordset, strSQL
>As String does not compile so I split the dim statement up into three
>seperate Dim statements as follows:
>Dim db As DAO.Database
>Dim rs As DAO.Recordset
>Dim strSQL As String
>>
>The first two dim statements cause a compiler error error User type not
>defined .
>I looked through the add in manager but found nothing there at all.
>>
>Where do I get the definitions?
>>
>Again, thanks
>>
>>
>"Keith Wilby" <here@there.comwrote in message
>news:492192f2$1_1@glkas0286.greenlnk.net... Quote:
>>"RICHARD BROMBERG" <dickbrom@worldnet.att.netwrote in message
>>news:XcgUk.31787$_Y1.6164@bgtnsc05-news.ops.worldnet.att.net...
>>>>
>>>>
>>>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 >>
>>
>
>
| | | | re: Populat a NewRecord from Text boxes Revisited
"RICHARD BROMBERG" <dickbrom@worldnet.att.netwrote in message
news:CjnUk.138572$Mh5.68250@bgtnsc04-news.ops.worldnet.att.net... Quote:
>
I am just learning and don't really have enough experience of insight to
determine the easiest or simplest way of doing things.
After I get the present program to work, I am going back and try the way
you suggest.
>
So you don't actually have a reason to be using an unbound form? If you're
a self-confessed newbie then I would urge you go with Larry's suggestion
pronto otherwise you're going to tie yourself in knots PDQ.
Keith. | | | | re: Populat a NewRecord from Text boxes Revisited
"Larry Linson" <bouncer@localhost.notwrote in
news:ERkUk.1144$4g5.387@nwrddc01.gnilink.net: Quote:
Access makes data entry and editing so trivially simple with bound
forms that I continue to be amazed, sixteen years after Access was
first released, how many people think they have to use unbound
forms and code to do these simple tasks -- when they are
re-implementing built-in features of the product.
To be fair, these are often refugees from database programming
environments in which it was impossible to use bound controls easily
or reliably. That would include, well, ever programming environment
but Access, I think.
--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/ | | | | re: Populat a NewRecord from Text boxes Revisited
"RICHARD BROMBERG" <dickbrom@worldnet.att.netwrote in
news:CjnUk.138572$Mh5.68250@bgtnsc04-news.ops.worldnet.att.net:
[to Larry's suggestion to simply use bound forms/controls:] Quote:
I am just learning and don't really have enough experience of
insight to determine the easiest or simplest way of doing things.
The approach that Larry suggest *is* the easiest and simplest way of
doing things. The whole point of Access is that you can build a
reasonably complex database application without ever writing one
line of code. It's point and click. That's the default orientation
of Access, and should have been the way you started out using it, as
everything about Access is designed to make it easy for
non-programmers. Quote:
After I get the present program to work, I am going back and try
the way you suggest.
Are you a masochist, or what?
I've been programming Access database applications professionally
since 1996 and the number of unbound data entry forms I've
programmed is fewer than a dozen. Yes, I have lots of unbound dialog
forms (often more of those than I have bound data editing forms). I
know how to write unbound forms, and you lose so many of Access's
capabilities in doing so that you gain no time, and only in the most
high-volume environments do you actually gain anything worth having
(higher concurrency is the only significant benefit).
Learn *Access*, rather than trying to use Access the way you've used
other development platforms. This means starting out trying to avoid
writing any code at all. Once you've done that, you'll be
well-equipped to create rich, reliable Access apps in the minimal
time.
--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/ |  | Similar Microsoft Access / VBA bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|