473,653 Members | 2,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populata NewRecord from Text boxes

I am using Access 2000 and I would like to make a data entry form
(frmDataEntry)

I want to append a newrecord to a table (tblPeople) and populate the new
record from two Textboxes (txtName and txtAge) The table has two fields,
Name and Age.

I used a command button (the command button wizard, record operations,Add
New Record) and it generates the code snippet below.

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

How do I refer to the Name and Age fields in the new record?

Help would be greatly appreciated.

*************** ***** snippet ***********
Private Sub commandAddRecor d_Click()

On Error GoTo Err_commandAddR ecord_Click
DoCmd.GoToRecor d , , acNewRec
'
' ?? move data from textboxes to table??
'
Exit_commandAdd Record_Click:
Exit Sub

Err_commandAddR ecord_Click:
MsgBox Err.Description
Resume Exit_commandAdd Record_Click

End Sub

*************** ***** snippet ***********
Nov 16 '08 #1
9 1686
RICHARD BROMBERG wrote:
I am using Access 2000 and I would like to make a data entry form
(frmDataEntry)

I want to append a newrecord to a table (tblPeople) and populate the new
record from two Textboxes (txtName and txtAge) The table has two fields,
Name and Age.

I used a command button (the command button wizard, record operations,Add
New Record) and it generates the code snippet below.

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

How do I refer to the Name and Age fields in the new record?

Help would be greatly appreciated.

*************** ***** snippet ***********
Private Sub commandAddRecor d_Click()

On Error GoTo Err_commandAddR ecord_Click
DoCmd.GoToRecor d , , acNewRec
'
' ?? move data from textboxes to table??
'
Exit_commandAdd Record_Click:
Exit Sub

Err_commandAddR ecord_Click:
MsgBox Err.Description
Resume Exit_commandAdd Record_Click

End Sub

*************** ***** snippet ***********

You could put, in the default value of Age, something like
=Forms!frmDataE ntry!txtAge
then
=Forms!fmrDataE ntry.txtName
for the name field.
Nov 16 '08 #2
Salad wrote:
RICHARD BROMBERG wrote:
>I am using Access 2000 and I would like to make a data entry form
(frmDataEntr y)

I want to append a newrecord to a table (tblPeople) and populate the
new record from two Textboxes (txtName and txtAge) The table has two
fields, Name and Age.

I used a command button (the command button wizard, record
operations,A dd New Record) and it generates the code snippet below.

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

How do I refer to the Name and Age fields in the new record?

Help would be greatly appreciated.

************** ****** snippet ***********
Private Sub commandAddRecor d_Click()

On Error GoTo Err_commandAddR ecord_Click
DoCmd.GoToRecor d , , acNewRec
'
' ?? move data from textboxes to table??
'
Exit_commandAd dRecord_Click:
Exit Sub

Err_commandAdd Record_Click:
MsgBox Err.Description
Resume Exit_commandAdd Record_Click

End Sub

************** ****** snippet ***********
You could put, in the default value of Age, something like
=Forms!frmDataE ntry!txtAge
then
=Forms!fmrDataE ntry.txtName
for the name field.
That's frm, not frm.
Nov 16 '08 #3
you have several issues here. first, you should rename the table field
called "Name", which is an Access Reserved Word and should NOT be used as
the name of anything *you* create in the database, including tables, fields,
queries, forms, reports, form/report controls, macros, modules and
procedures. for more information, see
http://home.att.net/~california.db/tips.html#aTip5.

next, a person's age is a calculated value based on his/her date of birth
subtracted from the current date. storing a calculated value in a table is
considered poor design. the only exception i can think of would be if the
record is historical data and you have a business need to know what the
person's age was *at that point in time*, rather than their current age.
even then, i'd probably date-stamp the record, and calculate the age using
that date, rather than storing a hard age value.

next, if you only have one field for the name, and if we're talking about
people here (not businesses, organizations, etc), then you are breaking
normalization rules, which require atomic data storage - separate fields for
first name, last name, middle name or initial if it's needed. suggest you
read up on relational design principles; for more information, see
http://home.att.net/~california.db/tips.html#aTip1.

now, having said all of the above, what is the RecordSource of frmDataEntry?
if the RecordSource is blank, then enter tblPeople in that property. now the
form is bound to tblPeople. set the ControlSource property of txtName to
Name, and the ControlSource of txtAge to Age. now you can just enter the
name and age in the form, and the values will be written to a new record in
the underlying table.

if frmDataEntry is already bound to another table (not tblPeople), you can
run an Append query to add the name and age to tblPeople (refer back to the
comments above re table design), as

CurrentDb.Execu te "INSERT INTO tblPeople ( Name, Age ) " _
& "SELECT '" & Me!txtName & "', " & Me!txtAge

the above SQL statement's syntax assumes that the Name field in tblPeople
has a Data Type of Text, and the Age field has a data type of Number.

but i strongly urge you to read up on relational design principles and
reconsider your table design before moving forward.

hth
"RICHARD BROMBERG" <di******@world net.att.netwrot e in message
news:Ie******** ************@bg tnsc04-news.ops.worldn et.att.net...
I am using Access 2000 and I would like to make a data entry form
(frmDataEntry)

I want to append a newrecord to a table (tblPeople) and populate the new
record from two Textboxes (txtName and txtAge) The table has two fields,
Name and Age.

I used a command button (the command button wizard, record operations,Add
New Record) and it generates the code snippet below.

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

How do I refer to the Name and Age fields in the new record?

Help would be greatly appreciated.

*************** ***** snippet ***********
Private Sub commandAddRecor d_Click()

On Error GoTo Err_commandAddR ecord_Click
DoCmd.GoToRecor d , , acNewRec
'
' ?? move data from textboxes to table??
'
Exit_commandAdd Record_Click:
Exit Sub

Err_commandAddR ecord_Click:
MsgBox Err.Description
Resume Exit_commandAdd Record_Click

End Sub

*************** ***** snippet ***********


Nov 16 '08 #4
Thanks

In the statement you suggest, copied below the parentheses are incorrect

CurrentDb.Execu te "INSERT INTO tblPeople ( Name, Age ) " _
& "SELECT '" & Me!txtName & "', " & Me!txtAge

"tina" <no****@address .comwrote in message
news:5F******** ************@bg tnsc04-news.ops.worldn et.att.net...
you have several issues here. first, you should rename the table field
called "Name", which is an Access Reserved Word and should NOT be used as
the name of anything *you* create in the database, including tables,
fields,
queries, forms, reports, form/report controls, macros, modules and
procedures. for more information, see
http://home.att.net/~california.db/tips.html#aTip5.

next, a person's age is a calculated value based on his/her date of birth
subtracted from the current date. storing a calculated value in a table is
considered poor design. the only exception i can think of would be if the
record is historical data and you have a business need to know what the
person's age was *at that point in time*, rather than their current age.
even then, i'd probably date-stamp the record, and calculate the age using
that date, rather than storing a hard age value.

next, if you only have one field for the name, and if we're talking about
people here (not businesses, organizations, etc), then you are breaking
normalization rules, which require atomic data storage - separate fields
for
first name, last name, middle name or initial if it's needed. suggest you
read up on relational design principles; for more information, see
http://home.att.net/~california.db/tips.html#aTip1.

now, having said all of the above, what is the RecordSource of
frmDataEntry?
if the RecordSource is blank, then enter tblPeople in that property. now
the
form is bound to tblPeople. set the ControlSource property of txtName to
Name, and the ControlSource of txtAge to Age. now you can just enter the
name and age in the form, and the values will be written to a new record
in
the underlying table.

if frmDataEntry is already bound to another table (not tblPeople), you can
run an Append query to add the name and age to tblPeople (refer back to
the
comments above re table design), as

CurrentDb.Execu te "INSERT INTO tblPeople ( Name, Age ) " _
& "SELECT '" & Me!txtName & "', " & Me!txtAge

the above SQL statement's syntax assumes that the Name field in tblPeople
has a Data Type of Text, and the Age field has a data type of Number.

but i strongly urge you to read up on relational design principles and
reconsider your table design before moving forward.

hth
"RICHARD BROMBERG" <di******@world net.att.netwrot e in message
news:Ie******** ************@bg tnsc04-news.ops.worldn et.att.net...
>I am using Access 2000 and I would like to make a data entry form
(frmDataEntr y)

I want to append a newrecord to a table (tblPeople) and populate the new
record from two Textboxes (txtName and txtAge) The table has two
fields,
Name and Age.

I used a command button (the command button wizard, record operations,Add
New Record) and it generates the code snippet below.

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

How do I refer to the Name and Age fields in the new record?

Help would be greatly appreciated.

************** ****** snippet ***********
Private Sub commandAddRecor d_Click()

On Error GoTo Err_commandAddR ecord_Click
DoCmd.GoToRecor d , , acNewRec
'
' ?? move data from textboxes to table??
'
Exit_commandAd dRecord_Click:
Exit Sub

Err_commandAdd Record_Click:
MsgBox Err.Description
Resume Exit_commandAdd Record_Click

End Sub

************** ****** snippet ***********



Nov 17 '08 #5
post your correction.
"RICHARD BROMBERG" <di******@world net.att.netwrot e in message
news:ij******** **********@bgtn sc05-news.ops.worldn et.att.net...
Thanks

In the statement you suggest, copied below the parentheses are incorrect

CurrentDb.Execu te "INSERT INTO tblPeople ( Name, Age ) " _
& "SELECT '" & Me!txtName & "', " & Me!txtAge

"tina" <no****@address .comwrote in message
news:5F******** ************@bg tnsc04-news.ops.worldn et.att.net...
you have several issues here. first, you should rename the table field
called "Name", which is an Access Reserved Word and should NOT be used
as
the name of anything *you* create in the database, including tables,
fields,
queries, forms, reports, form/report controls, macros, modules and
procedures. for more information, see
http://home.att.net/~california.db/tips.html#aTip5.

next, a person's age is a calculated value based on his/her date of
birth
subtracted from the current date. storing a calculated value in a table
is
considered poor design. the only exception i can think of would be if
the
record is historical data and you have a business need to know what the
person's age was *at that point in time*, rather than their current age.
even then, i'd probably date-stamp the record, and calculate the age
using
that date, rather than storing a hard age value.

next, if you only have one field for the name, and if we're talking
about
people here (not businesses, organizations, etc), then you are breaking
normalization rules, which require atomic data storage - separate fields
for
first name, last name, middle name or initial if it's needed. suggest
you
read up on relational design principles; for more information, see
http://home.att.net/~california.db/tips.html#aTip1.

now, having said all of the above, what is the RecordSource of
frmDataEntry?
if the RecordSource is blank, then enter tblPeople in that property. now
the
form is bound to tblPeople. set the ControlSource property of txtName to
Name, and the ControlSource of txtAge to Age. now you can just enter the
name and age in the form, and the values will be written to a new record
in
the underlying table.

if frmDataEntry is already bound to another table (not tblPeople), you
can
run an Append query to add the name and age to tblPeople (refer back to
the
comments above re table design), as

CurrentDb.Execu te "INSERT INTO tblPeople ( Name, Age ) " _
& "SELECT '" & Me!txtName & "', " & Me!txtAge

the above SQL statement's syntax assumes that the Name field in
tblPeople
has a Data Type of Text, and the Age field has a data type of Number.

but i strongly urge you to read up on relational design principles and
reconsider your table design before moving forward.

hth
"RICHARD BROMBERG" <di******@world net.att.netwrot e in message
news:Ie******** ************@bg tnsc04-news.ops.worldn et.att.net...
I am using Access 2000 and I would like to make a data entry form
(frmDataEntry)

I want to append a newrecord to a table (tblPeople) and populate the
new
record from two Textboxes (txtName and txtAge) The table has two
fields,
Name and Age.

I used a command button (the command button wizard, record
operations,Add
New Record) and it generates the code snippet below.

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

How do I refer to the Name and Age fields in the new record?

Help would be greatly appreciated.

*************** ***** snippet ***********
Private Sub commandAddRecor d_Click()

On Error GoTo Err_commandAddR ecord_Click
DoCmd.GoToRecor d , , acNewRec
'
' ?? move data from textboxes to table??
'
Exit_commandAdd Record_Click:
Exit Sub

Err_commandAddR ecord_Click:
MsgBox Err.Description
Resume Exit_commandAdd Record_Click

End Sub

*************** ***** snippet ***********



Nov 17 '08 #6
"tina" <no****@address .comwrote in message
news:Ry******** ***********@bgt nsc05-news.ops.worldn et.att.net...
post your correction.
Some ppl have no clue how to ask for help from complete strangers for free.

Nov 17 '08 #7
well, i really wanted to see the correction. i copied/pasted the SQL from a
test Append query, as i am wont to do in my day-to-day work - SQL not being
my strongest area. since the test query ran and i didn't change the syntax,
i'm at a loss. do you see the error, Keith? tia, tina
"Keith Wilby" <he**@there.com wrote in message
news:49******** **@glkas0286.gr eenlnk.net...
"tina" <no****@address .comwrote in message
news:Ry******** ***********@bgt nsc05-news.ops.worldn et.att.net...
post your correction.

Some ppl have no clue how to ask for help from complete strangers for
free.
>

Nov 18 '08 #8
"tina" <no****@address .comwrote in message
news:O_******** **********@bgtn sc05-news.ops.worldn et.att.net...
well, i really wanted to see the correction. i copied/pasted the SQL from
a
test Append query, as i am wont to do in my day-to-day work - SQL not
being
my strongest area. since the test query ran and i didn't change the
syntax,
i'm at a loss. do you see the error, Keith? tia, tina

I saw no error with the parentheses but having looked again I think it
should read

"INSERT INTO tblPeople ( Name, Age ) Values ('" & Me.txtName & "', " &
Me.txtAge & ")"

Keith.
www.keithwilby.co.uk

Nov 18 '08 #9
hmm, well, the SELECT does work - that's what i always use. do you know if
there's an upside/downside to SELECT vs Values? tia, tina
"Keith Wilby" <he**@there.com wrote in message
news:49******** **@glkas0286.gr eenlnk.net...
"tina" <no****@address .comwrote in message
news:O_******** **********@bgtn sc05-news.ops.worldn et.att.net...
well, i really wanted to see the correction. i copied/pasted the SQL
from
a
test Append query, as i am wont to do in my day-to-day work - SQL not
being
my strongest area. since the test query ran and i didn't change the
syntax,
i'm at a loss. do you see the error, Keith? tia, tina

I saw no error with the parentheses but having looked again I think it
should read

"INSERT INTO tblPeople ( Name, Age ) Values ('" & Me.txtName & "', " &
Me.txtAge & ")"

Keith.
www.keithwilby.co.uk

Nov 19 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6296
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by the choice from the drop down box. Something like: <form name="populatefrm" id="contactfrm" method="post"
7
8644
by: Gertjan van Heijst | last post by:
Hi, I really hope someone can help me because I've already spend 2 days on this problem and I'm not getting anywhere. I think the problem is that I don't really understand how text boxes store 'empty' values. I'm trying tot do the following. I have a continous sub form that lists transactions. On the top level form I have some text boxes to let the user specify the transactions between which dates should be listed. To do this I have...
4
2394
by: Sigurd Bruteig | last post by:
If i type NewRecord in some code, VB change to newrecord with lower-case letter. If I open a new database on the same computer the NewRecord keyword act normally. Ha anybody experienced something like this?? TIA Sigurd
2
8938
by: John Kreps | last post by:
(acc 2002) I've got six unbound text boxes on a subform that has a white background. Each of those six boxes has an expression that when true, will change its background from white to another color. These text boxes need to go behind a single line of other bound text boxes (which show the actual record). I.e., the purpose of the unbound text boxes w/conditional formatting is to highlight the record/background with one of six colors.
2
1791
by: Gary | last post by:
Hello All, I have an editable data grid in my web form, this grid allows the user to add new records, edit existing records and also delete them. When a user adds a record the grid goes in to edit mode and four text boxes appear, one is for the start date, another for an end date and the other two are for other data, the user fills in the fields and saves the data, all is great at this point, an entry is added ok. However the problem I...
11
16246
by: Edson Peacock | last post by:
I have a report with sub reports, one of the subreports have 12 text boxes that are 2" high and I want them all to grow if one goes to 3" high. If anyone has any suggestions they are very much appreciated. Thanks
4
2284
by: Andrew Meador - ASCPA, MCSE, MCP+I, Network+, A+ | last post by:
I have created a report. This report needs to display records between two dates entered by the user. I put two text boxes on the report so I can enter the start and end date - I set them to use an input mask of 'short date' format. The problem is that when I enter anything in these text boxes, as soon as the field looses focus, the text is cleared out - thus the text box is left blank. I have a button on the form that calls the requery...
9
2080
by: RICHARD BROMBERG | last post by:
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)
11
5155
by: jwessner | last post by:
I have a form (Form1) which contains basic Project data and a subform listing the personnel assigned to the Project as a continuous form. Selecting a person on that project and clicking on a command button will open a new form (Form2). Form2 has two subforms. Both are embedded in the main form. (Subform2 is NOT embedded in subform1.) Subform1 displays records as a continuous form based on the Primary ID of the main form and lists the...
0
8283
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8590
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5620
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2707
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.