adding new (blank) record to child/sub-form on main form

T

Ted

in my a2k app'n, i have a form (Audit Reports), the 'main form', on which
there are two child/sub-forms, 'Evaluations' and 'Patients'. for now, i would
like to create a pair of command buttons on the Audit Reports form. each one
which will add a new/blank record into the control sources behind its
respective form. in both instances, the 'Add records' property of the
form/sub-form will be
set to 'No' so that user cannot add record w/o using the button provided.

i currently experimenting with a button to handle the 'Evaluations' form;
the code is below:

Private Sub AddAudit_Click()
On Error GoTo Err_AddAudit_Click
Forms![Audit Report]![Evaluations].AllowAdditions = True
DoCmd.GoToRecord acDataForm, Forms![Audit Report]![Evaluations], acNewRec
Forms![Audit Report]![Evaluations].AllowAdditions = False
Exit_AddAudit_Click:
Exit Sub

Err_AddAudit_Click:
MsgBox Err.description
Resume Exit_AddAudit_Click
End Sub

i guess i'm newbie enough not to understand what 'Object does not support
this object or method' (the received error message) means.

anyone out there care to help decode this. it'd be greatly appreciated.

thanks,

-ted
 
T

tina

well, you're getting that particular error because your reference to the
subform is incorrect. but, even when you fix that, your code still will not
allow the user to add a new record in the subform.

using the DoCmd.GoToRecord to move to a new record, does not *add* a new
record. *adding* a record means entering data in one or more fields and then
saving the record to the table.

with your code, you're setting AllowEditions to True, which makes a "blank"
record available so that you can enter data for a new record, you're setting
focus on the "blank" record, but then you're immediately setting
AllowEditions to False again, which effectively removes availability of the
"blank" record.

if your intention is to allow the user to only add one new record to a
subform at a time, and each time the user must click a command button to do
so, then there are probably several ways you could set it up. one way is to
set AllowAdditions to True, and move to the new record. after the user
enters data in the new record, you can then set the subform's AllowAdditions
property back to False. i haven't tested it, but you can probably use the
subform's AfterUpdate property to run code for that.

example of new code (below code assumes the subform and the command buttons
are both on the main form called AuditReport):

Private Sub AddAudit_Click()

With Me!Evaluations.Form
.AllowAdditions = True
DoCmd.RunCommand acCmdRecordsGoToNew
End With

End Sub

the above code goes in form AuditReport's form module.
note: make sure you're referring to the name of the subform *control* in
the main form, not the name of the subform object in the database window
(sometimes the names are the same, sometimes not). example: the name of the
subform object in the database window on the Forms tab is Evalualtions. the
name of the subform *control* in the main form is Child1. the code in the
main form's module must refer to Child1, as

Me!Child1.Form (instead of Me!Evaluations.Form)

the code below goes in the form module of the subform object, *not* the
module of the main form.

Private Sub Form_AfterUpdate()

Me.AllowAdditons = False

End Sub

hth


Ted said:
in my a2k app'n, i have a form (Audit Reports), the 'main form', on which
there are two child/sub-forms, 'Evaluations' and 'Patients'. for now, i would
like to create a pair of command buttons on the Audit Reports form. each one
which will add a new/blank record into the control sources behind its
respective form. in both instances, the 'Add records' property of the
form/sub-form will be
set to 'No' so that user cannot add record w/o using the button provided.

i currently experimenting with a button to handle the 'Evaluations' form;
the code is below:

Private Sub AddAudit_Click()
On Error GoTo Err_AddAudit_Click
Forms![Audit Report]![Evaluations].AllowAdditions = True
DoCmd.GoToRecord acDataForm, Forms![Audit Report]![Evaluations], acNewRec
Forms![Audit Report]![Evaluations].AllowAdditions = False
Exit_AddAudit_Click:
Exit Sub

Err_AddAudit_Click:
MsgBox Err.description
Resume Exit_AddAudit_Click
End Sub

i guess i'm newbie enough not to understand what 'Object does not support
this object or method' (the received error message) means.

anyone out there care to help decode this. it'd be greatly appreciated.

thanks,

-ted
 
T

Ted

hi tina,

i've finally gotten a chance to try to implement your proposed modifications
and wanted to get back with the results.....

here's the code behind the "AddAudit" button. the button sitos in the
'Details' section of the main form ("Audit Report"), just above where the
subform "Evaluations" appears.

Private Sub AddAudit_Click()
On Error GoTo Err_AddAudit_Click

With Me!Evaluations.Form
.AllowAdditions = True
DoCmd.RunCommand acCmdRecordsGoToNew
End With

Exit_AddAudit_Click:
Exit Sub

Err_AddAudit_Click:
MsgBox Err.description
Resume Exit_AddAudit_Click
End Sub

the following code was added to the "After Update" event of the
"Evaluations" form.

Private Sub Form_AfterUpdate()
Me.AllowAdditions = False
End Sub

when i click it, the following message displays

"The command or action 'RecordsToToNew' isn't available now"

i tried using your precautionary tale wrt the way the suboform is named and
substituted "Child1" for "Evaluations" in the topmost code and clicking on
the same button was greeted by

"Audit Reports can't find the field 'Child1' referred to in your expression"

before closing, i want to finish the description of the results of clicking
the button with the "Evaluations" name by adding that it results in the
activation of the add record asterisk "*" in the subform window and the
ability to actuall enter data and the 'pointer' sitting on the topmost record
in the subform/datasheet??

whatamidoinwrong?

tina said:
well, you're getting that particular error because your reference to the
subform is incorrect. but, even when you fix that, your code still will not
allow the user to add a new record in the subform.

using the DoCmd.GoToRecord to move to a new record, does not *add* a new
record. *adding* a record means entering data in one or more fields and then
saving the record to the table.

with your code, you're setting AllowEditions to True, which makes a "blank"
record available so that you can enter data for a new record, you're setting
focus on the "blank" record, but then you're immediately setting
AllowEditions to False again, which effectively removes availability of the
"blank" record.

if your intention is to allow the user to only add one new record to a
subform at a time, and each time the user must click a command button to do
so, then there are probably several ways you could set it up. one way is to
set AllowAdditions to True, and move to the new record. after the user
enters data in the new record, you can then set the subform's AllowAdditions
property back to False. i haven't tested it, but you can probably use the
subform's AfterUpdate property to run code for that.

example of new code (below code assumes the subform and the command buttons
are both on the main form called AuditReport):

Private Sub AddAudit_Click()

With Me!Evaluations.Form
.AllowAdditions = True
DoCmd.RunCommand acCmdRecordsGoToNew
End With

End Sub

the above code goes in form AuditReport's form module.
note: make sure you're referring to the name of the subform *control* in
the main form, not the name of the subform object in the database window
(sometimes the names are the same, sometimes not). example: the name of the
subform object in the database window on the Forms tab is Evalualtions. the
name of the subform *control* in the main form is Child1. the code in the
main form's module must refer to Child1, as

Me!Child1.Form (instead of Me!Evaluations.Form)

the code below goes in the form module of the subform object, *not* the
module of the main form.

Private Sub Form_AfterUpdate()

Me.AllowAdditons = False

End Sub

hth


Ted said:
in my a2k app'n, i have a form (Audit Reports), the 'main form', on which
there are two child/sub-forms, 'Evaluations' and 'Patients'. for now, i would
like to create a pair of command buttons on the Audit Reports form. each one
which will add a new/blank record into the control sources behind its
respective form. in both instances, the 'Add records' property of the
form/sub-form will be
set to 'No' so that user cannot add record w/o using the button provided.

i currently experimenting with a button to handle the 'Evaluations' form;
the code is below:

Private Sub AddAudit_Click()
On Error GoTo Err_AddAudit_Click
Forms![Audit Report]![Evaluations].AllowAdditions = True
DoCmd.GoToRecord acDataForm, Forms![Audit Report]![Evaluations], acNewRec
Forms![Audit Report]![Evaluations].AllowAdditions = False
Exit_AddAudit_Click:
Exit Sub

Err_AddAudit_Click:
MsgBox Err.description
Resume Exit_AddAudit_Click
End Sub

i guess i'm newbie enough not to understand what 'Object does not support
this object or method' (the received error message) means.

anyone out there care to help decode this. it'd be greatly appreciated.

thanks,

-ted
 
T

tina

i tested my suggested code, and got the same error message that you got. so
i tried changing the code to

Me!Child4.Form.AllowAdditions = True
Me!Child4.SetFocus
DoCmd.RunCommand acCmdRecordsGoToNew

this time it worked correctly. Child4 is the name of my subform control
(frmMain_Sub is the name of my subform object, but that name is not used in
this code at all).
i tried using your precautionary tale wrt the way the suboform
is named and substituted "Child1" for "Evaluations" in the
topmost code

re above comment: substituting "Child1" would not work unless that is
actually the name of your subform control. to find the correct name of your
subform control, do the following:

1. open the main form in design view.
2. click on the subform (within the main form design view) to select it.
3. open the Properties box and click on the Other tab.
4. look at the Name property.

hth


Ted said:
hi tina,

i've finally gotten a chance to try to implement your proposed modifications
and wanted to get back with the results.....

here's the code behind the "AddAudit" button. the button sitos in the
'Details' section of the main form ("Audit Report"), just above where the
subform "Evaluations" appears.

Private Sub AddAudit_Click()
On Error GoTo Err_AddAudit_Click

With Me!Evaluations.Form
.AllowAdditions = True
DoCmd.RunCommand acCmdRecordsGoToNew
End With

Exit_AddAudit_Click:
Exit Sub

Err_AddAudit_Click:
MsgBox Err.description
Resume Exit_AddAudit_Click
End Sub

the following code was added to the "After Update" event of the
"Evaluations" form.

Private Sub Form_AfterUpdate()
Me.AllowAdditions = False
End Sub

when i click it, the following message displays

"The command or action 'RecordsToToNew' isn't available now"

i tried using your precautionary tale wrt the way the suboform is named and
substituted "Child1" for "Evaluations" in the topmost code and clicking on
the same button was greeted by

"Audit Reports can't find the field 'Child1' referred to in your expression"

before closing, i want to finish the description of the results of clicking
the button with the "Evaluations" name by adding that it results in the
activation of the add record asterisk "*" in the subform window and the
ability to actuall enter data and the 'pointer' sitting on the topmost record
in the subform/datasheet??

whatamidoinwrong?

tina said:
well, you're getting that particular error because your reference to the
subform is incorrect. but, even when you fix that, your code still will not
allow the user to add a new record in the subform.

using the DoCmd.GoToRecord to move to a new record, does not *add* a new
record. *adding* a record means entering data in one or more fields and then
saving the record to the table.

with your code, you're setting AllowEditions to True, which makes a "blank"
record available so that you can enter data for a new record, you're setting
focus on the "blank" record, but then you're immediately setting
AllowEditions to False again, which effectively removes availability of the
"blank" record.

if your intention is to allow the user to only add one new record to a
subform at a time, and each time the user must click a command button to do
so, then there are probably several ways you could set it up. one way is to
set AllowAdditions to True, and move to the new record. after the user
enters data in the new record, you can then set the subform's AllowAdditions
property back to False. i haven't tested it, but you can probably use the
subform's AfterUpdate property to run code for that.

example of new code (below code assumes the subform and the command buttons
are both on the main form called AuditReport):

Private Sub AddAudit_Click()

With Me!Evaluations.Form
.AllowAdditions = True
DoCmd.RunCommand acCmdRecordsGoToNew
End With

End Sub

the above code goes in form AuditReport's form module.
note: make sure you're referring to the name of the subform *control* in
the main form, not the name of the subform object in the database window
(sometimes the names are the same, sometimes not). example: the name of the
subform object in the database window on the Forms tab is Evalualtions. the
name of the subform *control* in the main form is Child1. the code in the
main form's module must refer to Child1, as

Me!Child1.Form (instead of Me!Evaluations.Form)

the code below goes in the form module of the subform object, *not* the
module of the main form.

Private Sub Form_AfterUpdate()

Me.AllowAdditons = False

End Sub

hth


Ted said:
in my a2k app'n, i have a form (Audit Reports), the 'main form', on which
there are two child/sub-forms, 'Evaluations' and 'Patients'. for now,
i
would
like to create a pair of command buttons on the Audit Reports form.
each
one
which will add a new/blank record into the control sources behind its
respective form. in both instances, the 'Add records' property of the
form/sub-form will be
set to 'No' so that user cannot add record w/o using the button provided.

i currently experimenting with a button to handle the 'Evaluations' form;
the code is below:

Private Sub AddAudit_Click()
On Error GoTo Err_AddAudit_Click
Forms![Audit Report]![Evaluations].AllowAdditions = True
DoCmd.GoToRecord acDataForm, Forms![Audit Report]![Evaluations], acNewRec
Forms![Audit Report]![Evaluations].AllowAdditions = False
Exit_AddAudit_Click:
Exit Sub

Err_AddAudit_Click:
MsgBox Err.description
Resume Exit_AddAudit_Click
End Sub

i guess i'm newbie enough not to understand what 'Object does not support
this object or method' (the received error message) means.

anyone out there care to help decode this. it'd be greatly appreciated.

thanks,

-ted
 
T

Ted

hiya tina,

all the best wishes and regards. couldn't done this w/o your input(s).

do i need to actaully say it worked on mine as well!!!!

:)

-ted

tina said:
i tested my suggested code, and got the same error message that you got. so
i tried changing the code to

Me!Child4.Form.AllowAdditions = True
Me!Child4.SetFocus
DoCmd.RunCommand acCmdRecordsGoToNew

this time it worked correctly. Child4 is the name of my subform control
(frmMain_Sub is the name of my subform object, but that name is not used in
this code at all).
i tried using your precautionary tale wrt the way the suboform
is named and substituted "Child1" for "Evaluations" in the
topmost code

re above comment: substituting "Child1" would not work unless that is
actually the name of your subform control. to find the correct name of your
subform control, do the following:

1. open the main form in design view.
2. click on the subform (within the main form design view) to select it.
3. open the Properties box and click on the Other tab.
4. look at the Name property.

hth


Ted said:
hi tina,

i've finally gotten a chance to try to implement your proposed modifications
and wanted to get back with the results.....

here's the code behind the "AddAudit" button. the button sitos in the
'Details' section of the main form ("Audit Report"), just above where the
subform "Evaluations" appears.

Private Sub AddAudit_Click()
On Error GoTo Err_AddAudit_Click

With Me!Evaluations.Form
.AllowAdditions = True
DoCmd.RunCommand acCmdRecordsGoToNew
End With

Exit_AddAudit_Click:
Exit Sub

Err_AddAudit_Click:
MsgBox Err.description
Resume Exit_AddAudit_Click
End Sub

the following code was added to the "After Update" event of the
"Evaluations" form.

Private Sub Form_AfterUpdate()
Me.AllowAdditions = False
End Sub

when i click it, the following message displays

"The command or action 'RecordsToToNew' isn't available now"

i tried using your precautionary tale wrt the way the suboform is named and
substituted "Child1" for "Evaluations" in the topmost code and clicking on
the same button was greeted by

"Audit Reports can't find the field 'Child1' referred to in your expression"

before closing, i want to finish the description of the results of clicking
the button with the "Evaluations" name by adding that it results in the
activation of the add record asterisk "*" in the subform window and the
ability to actuall enter data and the 'pointer' sitting on the topmost record
in the subform/datasheet??

whatamidoinwrong?

tina said:
well, you're getting that particular error because your reference to the
subform is incorrect. but, even when you fix that, your code still will not
allow the user to add a new record in the subform.

using the DoCmd.GoToRecord to move to a new record, does not *add* a new
record. *adding* a record means entering data in one or more fields and then
saving the record to the table.

with your code, you're setting AllowEditions to True, which makes a "blank"
record available so that you can enter data for a new record, you're setting
focus on the "blank" record, but then you're immediately setting
AllowEditions to False again, which effectively removes availability of the
"blank" record.

if your intention is to allow the user to only add one new record to a
subform at a time, and each time the user must click a command button to do
so, then there are probably several ways you could set it up. one way is to
set AllowAdditions to True, and move to the new record. after the user
enters data in the new record, you can then set the subform's AllowAdditions
property back to False. i haven't tested it, but you can probably use the
subform's AfterUpdate property to run code for that.

example of new code (below code assumes the subform and the command buttons
are both on the main form called AuditReport):

Private Sub AddAudit_Click()

With Me!Evaluations.Form
.AllowAdditions = True
DoCmd.RunCommand acCmdRecordsGoToNew
End With

End Sub

the above code goes in form AuditReport's form module.
note: make sure you're referring to the name of the subform *control* in
the main form, not the name of the subform object in the database window
(sometimes the names are the same, sometimes not). example: the name of the
subform object in the database window on the Forms tab is Evalualtions. the
name of the subform *control* in the main form is Child1. the code in the
main form's module must refer to Child1, as

Me!Child1.Form (instead of Me!Evaluations.Form)

the code below goes in the form module of the subform object, *not* the
module of the main form.

Private Sub Form_AfterUpdate()

Me.AllowAdditons = False

End Sub

hth


in my a2k app'n, i have a form (Audit Reports), the 'main form', on which
there are two child/sub-forms, 'Evaluations' and 'Patients'. for now, i
would
like to create a pair of command buttons on the Audit Reports form. each
one
which will add a new/blank record into the control sources behind its
respective form. in both instances, the 'Add records' property of the
form/sub-form will be
set to 'No' so that user cannot add record w/o using the button provided.

i currently experimenting with a button to handle the 'Evaluations' form;
the code is below:

Private Sub AddAudit_Click()
On Error GoTo Err_AddAudit_Click
Forms![Audit Report]![Evaluations].AllowAdditions = True
DoCmd.GoToRecord acDataForm, Forms![Audit Report]![Evaluations],
acNewRec
Forms![Audit Report]![Evaluations].AllowAdditions = False
Exit_AddAudit_Click:
Exit Sub

Err_AddAudit_Click:
MsgBox Err.description
Resume Exit_AddAudit_Click
End Sub

i guess i'm newbie enough not to understand what 'Object does not support
this object or method' (the received error message) means.

anyone out there care to help decode this. it'd be greatly appreciated.

thanks,

-ted
 
T

tina

subforms can be tricky until you get the hang of them. glad to help. :)


Ted said:
hiya tina,

all the best wishes and regards. couldn't done this w/o your input(s).

do i need to actaully say it worked on mine as well!!!!

:)

-ted

tina said:
i tested my suggested code, and got the same error message that you got. so
i tried changing the code to

Me!Child4.Form.AllowAdditions = True
Me!Child4.SetFocus
DoCmd.RunCommand acCmdRecordsGoToNew

this time it worked correctly. Child4 is the name of my subform control
(frmMain_Sub is the name of my subform object, but that name is not used in
this code at all).
i tried using your precautionary tale wrt the way the suboform
is named and substituted "Child1" for "Evaluations" in the
topmost code

re above comment: substituting "Child1" would not work unless that is
actually the name of your subform control. to find the correct name of your
subform control, do the following:

1. open the main form in design view.
2. click on the subform (within the main form design view) to select it.
3. open the Properties box and click on the Other tab.
4. look at the Name property.

hth


Ted said:
hi tina,

i've finally gotten a chance to try to implement your proposed modifications
and wanted to get back with the results.....

here's the code behind the "AddAudit" button. the button sitos in the
'Details' section of the main form ("Audit Report"), just above where the
subform "Evaluations" appears.

Private Sub AddAudit_Click()
On Error GoTo Err_AddAudit_Click

With Me!Evaluations.Form
.AllowAdditions = True
DoCmd.RunCommand acCmdRecordsGoToNew
End With

Exit_AddAudit_Click:
Exit Sub

Err_AddAudit_Click:
MsgBox Err.description
Resume Exit_AddAudit_Click
End Sub

the following code was added to the "After Update" event of the
"Evaluations" form.

Private Sub Form_AfterUpdate()
Me.AllowAdditions = False
End Sub

when i click it, the following message displays

"The command or action 'RecordsToToNew' isn't available now"

i tried using your precautionary tale wrt the way the suboform is
named
and
substituted "Child1" for "Evaluations" in the topmost code and clicking on
the same button was greeted by

"Audit Reports can't find the field 'Child1' referred to in your expression"

before closing, i want to finish the description of the results of clicking
the button with the "Evaluations" name by adding that it results in the
activation of the add record asterisk "*" in the subform window and the
ability to actuall enter data and the 'pointer' sitting on the topmost record
in the subform/datasheet??

whatamidoinwrong?

:

well, you're getting that particular error because your reference to the
subform is incorrect. but, even when you fix that, your code still
will
not
allow the user to add a new record in the subform.

using the DoCmd.GoToRecord to move to a new record, does not *add* a new
record. *adding* a record means entering data in one or more fields
and
then
saving the record to the table.

with your code, you're setting AllowEditions to True, which makes a "blank"
record available so that you can enter data for a new record, you're setting
focus on the "blank" record, but then you're immediately setting
AllowEditions to False again, which effectively removes availability
of
the
"blank" record.

if your intention is to allow the user to only add one new record to a
subform at a time, and each time the user must click a command
button to
do
so, then there are probably several ways you could set it up. one
way is
to
set AllowAdditions to True, and move to the new record. after the user
enters data in the new record, you can then set the subform's AllowAdditions
property back to False. i haven't tested it, but you can probably
use
the
subform's AfterUpdate property to run code for that.

example of new code (below code assumes the subform and the command buttons
are both on the main form called AuditReport):

Private Sub AddAudit_Click()

With Me!Evaluations.Form
.AllowAdditions = True
DoCmd.RunCommand acCmdRecordsGoToNew
End With

End Sub

the above code goes in form AuditReport's form module.
note: make sure you're referring to the name of the subform
*control*
in
the main form, not the name of the subform object in the database window
(sometimes the names are the same, sometimes not). example: the name
of
the
subform object in the database window on the Forms tab is
Evalualtions.
the
name of the subform *control* in the main form is Child1. the code
in
the
main form's module must refer to Child1, as

Me!Child1.Form (instead of Me!Evaluations.Form)

the code below goes in the form module of the subform object, *not* the
module of the main form.

Private Sub Form_AfterUpdate()

Me.AllowAdditons = False

End Sub

hth


in my a2k app'n, i have a form (Audit Reports), the 'main form',
on
which
there are two child/sub-forms, 'Evaluations' and 'Patients'. for
now,
i
would
like to create a pair of command buttons on the Audit Reports
form.
each
one
which will add a new/blank record into the control sources behind its
respective form. in both instances, the 'Add records' property of the
form/sub-form will be
set to 'No' so that user cannot add record w/o using the button provided.

i currently experimenting with a button to handle the
'Evaluations'
form;
the code is below:

Private Sub AddAudit_Click()
On Error GoTo Err_AddAudit_Click
Forms![Audit Report]![Evaluations].AllowAdditions = True
DoCmd.GoToRecord acDataForm, Forms![Audit Report]![Evaluations],
acNewRec
Forms![Audit Report]![Evaluations].AllowAdditions = False
Exit_AddAudit_Click:
Exit Sub

Err_AddAudit_Click:
MsgBox Err.description
Resume Exit_AddAudit_Click
End Sub

i guess i'm newbie enough not to understand what 'Object does not support
this object or method' (the received error message) means.

anyone out there care to help decode this. it'd be greatly appreciated.

thanks,

-ted
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top