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 *********** | | | | re: Populata NewRecord from Text boxes
RICHARD BROMBERG wrote: Quote:
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. | | | | re: Populata NewRecord from Text boxes
Salad wrote: Quote:
RICHARD BROMBERG wrote:
> Quote:
>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. | | | | re: Populata NewRecord from Text boxes
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" <dickbrom@worldnet.att.netwrote in message
news:IeXTk.135606$Mh5.97332@bgtnsc04-news.ops.worldnet.att.net... Quote:
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 Quote:
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 ***********
>
>
| | | | re: Populata NewRecord from Text boxes
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" <nospam@address.comwrote in message
news:5FYTk.135770$Mh5.71774@bgtnsc04-news.ops.worldnet.att.net... Quote:
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" <dickbrom@worldnet.att.netwrote in message
news:IeXTk.135606$Mh5.97332@bgtnsc04-news.ops.worldnet.att.net... Quote:
>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 Quote:
>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 ***********
>>
>>
>
>
| | | | re: Populata NewRecord from Text boxes
post your correction.
"RICHARD BROMBERG" <dickbrom@worldnet.att.netwrote in message
news:ijeUk.31667$_Y1.4083@bgtnsc05-news.ops.worldnet.att.net... Quote:
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" <nospam@address.comwrote in message
news:5FYTk.135770$Mh5.71774@bgtnsc04-news.ops.worldnet.att.net... Quote:
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 Quote: Quote:
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 Quote: Quote:
subtracted from the current date. storing a calculated value in a table
is Quote: Quote:
considered poor design. the only exception i can think of would be if
the Quote: Quote:
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 Quote: Quote:
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 Quote: Quote:
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 Quote: Quote:
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 Quote: Quote:
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 Quote: Quote:
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" <dickbrom@worldnet.att.netwrote in message
news:IeXTk.135606$Mh5.97332@bgtnsc04-news.ops.worldnet.att.net... Quote:
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 Quote: Quote: Quote:
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 Quote: Quote: Quote:
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 Quote: Quote:
in Quote:
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 ***********
>
>
>
>
| | | | re: Populata NewRecord from Text boxes
"tina" <nospam@address.comwrote in message
news:RyfUk.31743$_Y1.29827@bgtnsc05-news.ops.worldnet.att.net... Quote:
post your correction.
>
Some ppl have no clue how to ask for help from complete strangers for free. | | | | re: Populata NewRecord from Text boxes
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" <here@there.comwrote in message
news:49218f09$1_1@glkas0286.greenlnk.net... Quote:
"tina" <nospam@address.comwrote in message
news:RyfUk.31743$_Y1.29827@bgtnsc05-news.ops.worldnet.att.net... Quote:
post your correction.
>
Some ppl have no clue how to ask for help from complete strangers for
free. | | | | re: Populata NewRecord from Text boxes
"tina" <nospam@address.comwrote in message
news:O_qUk.32499$_Y1.3595@bgtnsc05-news.ops.worldnet.att.net... Quote:
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 | | | | re: Populata NewRecord from Text boxes
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" <here@there.comwrote in message
news:49227f95$1_1@glkas0286.greenlnk.net... Quote:
"tina" <nospam@address.comwrote in message
news:O_qUk.32499$_Y1.3595@bgtnsc05-news.ops.worldnet.att.net... Quote:
well, i really wanted to see the correction. i copied/pasted the SQL
from Quote: Quote:
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
>
|  | 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,467 network members.
|