473,387 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 commandAddRecord_Click()

On Error GoTo Err_commandAddRecord_Click
DoCmd.GoToRecord , , acNewRec
'
' ?? move data from textboxes to table??
'
Exit_commandAddRecord_Click:
Exit Sub

Err_commandAddRecord_Click:
MsgBox Err.Description
Resume Exit_commandAddRecord_Click

End Sub

******************** snippet ***********
Nov 16 '08 #1
9 1668
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 commandAddRecord_Click()

On Error GoTo Err_commandAddRecord_Click
DoCmd.GoToRecord , , acNewRec
'
' ?? move data from textboxes to table??
'
Exit_commandAddRecord_Click:
Exit Sub

Err_commandAddRecord_Click:
MsgBox Err.Description
Resume Exit_commandAddRecord_Click

End Sub

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

You could put, in the default value of Age, something like
=Forms!frmDataEntry!txtAge
then
=Forms!fmrDataEntry.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
(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 commandAddRecord_Click()

On Error GoTo Err_commandAddRecord_Click
DoCmd.GoToRecord , , acNewRec
'
' ?? move data from textboxes to table??
'
Exit_commandAddRecord_Click:
Exit Sub

Err_commandAddRecord_Click:
MsgBox Err.Description
Resume Exit_commandAddRecord_Click

End Sub

******************** snippet ***********
You could put, in the default value of Age, something like
=Forms!frmDataEntry!txtAge
then
=Forms!fmrDataEntry.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.Execute "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******@worldnet.att.netwrote in message
news:Ie********************@bgtnsc04-news.ops.worldnet.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 commandAddRecord_Click()

On Error GoTo Err_commandAddRecord_Click
DoCmd.GoToRecord , , acNewRec
'
' ?? move data from textboxes to table??
'
Exit_commandAddRecord_Click:
Exit Sub

Err_commandAddRecord_Click:
MsgBox Err.Description
Resume Exit_commandAddRecord_Click

End Sub

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


Nov 16 '08 #4
Thanks

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

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

"tina" <no****@address.comwrote in message
news:5F********************@bgtnsc04-news.ops.worldnet.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.Execute "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******@worldnet.att.netwrote in message
news:Ie********************@bgtnsc04-news.ops.worldnet.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 commandAddRecord_Click()

On Error GoTo Err_commandAddRecord_Click
DoCmd.GoToRecord , , acNewRec
'
' ?? move data from textboxes to table??
'
Exit_commandAddRecord_Click:
Exit Sub

Err_commandAddRecord_Click:
MsgBox Err.Description
Resume Exit_commandAddRecord_Click

End Sub

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



Nov 17 '08 #5
post your correction.
"RICHARD BROMBERG" <di******@worldnet.att.netwrote in message
news:ij******************@bgtnsc05-news.ops.worldnet.att.net...
Thanks

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

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

"tina" <no****@address.comwrote in message
news:5F********************@bgtnsc04-news.ops.worldnet.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.Execute "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******@worldnet.att.netwrote in message
news:Ie********************@bgtnsc04-news.ops.worldnet.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 commandAddRecord_Click()

On Error GoTo Err_commandAddRecord_Click
DoCmd.GoToRecord , , acNewRec
'
' ?? move data from textboxes to table??
'
Exit_commandAddRecord_Click:
Exit Sub

Err_commandAddRecord_Click:
MsgBox Err.Description
Resume Exit_commandAddRecord_Click

End Sub

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



Nov 17 '08 #6
"tina" <no****@address.comwrote in message
news:Ry*******************@bgtnsc05-news.ops.worldnet.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.comwrote in message
news:49**********@glkas0286.greenlnk.net...
"tina" <no****@address.comwrote in message
news:Ry*******************@bgtnsc05-news.ops.worldnet.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_******************@bgtnsc05-news.ops.worldnet.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.comwrote in message
news:49**********@glkas0286.greenlnk.net...
"tina" <no****@address.comwrote in message
news:O_******************@bgtnsc05-news.ops.worldnet.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
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...
7
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...
4
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...
2
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...
2
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...
11
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...
4
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...
9
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...
11
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.