Identify a subform in Code

B

Bob Quintal

=?Utf-8?B?Wm9sdGFyNTQ=?= <[email protected]>
wrote in
Can someone tell me how to identify a field on a subform using
code? I am trying to create a routine that, when a customer
is entered into the main form and they are not in the list,
the subform will accept a new entry.

Currently I know that when specifying field names on a main
form I can simply type the field name or use Me.[fieldname].
To refer to a subform can I use subfrmName.[fieldname]?

Z
to refer to a control on the subform you have to reference the
subform control's name property which may not be the same as the
sub's form name. You will find the subform control's name
property
in the properties, under the other tab as name, the name of the
sub's form is in the properties Data tab as Control source.

That said,

me!child1.form![fieldname]
 
G

Guest

Can someone tell me how to identify a field on a subform using code? I am
trying to create a routine that, when a customer is entered into the main
form and they are not in the list, the subform will accept a new entry.

Currently I know that when specifying field names on a main form I can
simply type the field name or use Me.[fieldname]. To refer to a subform can
I use subfrmName.[fieldname]?

Z
 
K

kingston via AccessMonster.com

This might help:

http://www.mvps.org/access/forms/frm0031.htm

Can someone tell me how to identify a field on a subform using code? I am
trying to create a routine that, when a customer is entered into the main
form and they are not in the list, the subform will accept a new entry.

Currently I know that when specifying field names on a main form I can
simply type the field name or use Me.[fieldname]. To refer to a subform can
I use subfrmName.[fieldname]?

Z
 
K

Keith Wilby

Zoltar54 said:
Can someone tell me how to identify a field on a subform using code? I am
trying to create a routine that, when a customer is entered into the main
form and they are not in the list, the subform will accept a new entry.

Currently I know that when specifying field names on a main form I can
simply type the field name or use Me.[fieldname]. To refer to a subform
can
I use subfrmName.[fieldname]?

Z

IIRC:

[Forms]![frmMain]![sfrmSub].ctlControl

Keith.
www.keithwilby.com
 
G

Guest

Just for clarification, would I then type:

me!subfrmCustomer.form![customerid] = newdata

so as to allow me to enter a new customer name and have that added to the
underlying tblCustomer table? (I have a number of other fileds such as Name,
Address etc.. for which, I assume the same process would apply).



Bob Quintal said:
=?Utf-8?B?Wm9sdGFyNTQ=?= <[email protected]>
wrote in
Can someone tell me how to identify a field on a subform using
code? I am trying to create a routine that, when a customer
is entered into the main form and they are not in the list,
the subform will accept a new entry.

Currently I know that when specifying field names on a main
form I can simply type the field name or use Me.[fieldname].
To refer to a subform can I use subfrmName.[fieldname]?

Z
to refer to a control on the subform you have to reference the
subform control's name property which may not be the same as the
sub's form name. You will find the subform control's name
property
in the properties, under the other tab as name, the name of the
sub's form is in the properties Data tab as Control source.

That said,

me!child1.form![fieldname]
 
B

Bob Quintal

=?Utf-8?B?Wm9sdGFyNTQ=?= <[email protected]>
wrote in
Just for clarification, would I then type:

me!subfrmCustomer.form![customerid] = newdata

so as to allow me to enter a new customer name and have that
added to the underlying tblCustomer table? (I have a number of
other fileds such as Name, Address etc.. for which, I assume
the same process would apply).
if subfrmCustomer is both the name of the subform control and
the name of the form in the control, yes. If the two are
different, use the name of the control, not the form

Bob Quintal said:
=?Utf-8?B?Wm9sdGFyNTQ=?= <[email protected]>
wrote in
Can someone tell me how to identify a field on a subform
using code? I am trying to create a routine that, when a
customer is entered into the main form and they are not in
the list, the subform will accept a new entry.

Currently I know that when specifying field names on a main
form I can simply type the field name or use
Me.[fieldname]. To refer to a subform can I use
subfrmName.[fieldname]?

Z
to refer to a control on the subform you have to reference
the subform control's name property which may not be the same
as the sub's form name. You will find the subform control's
name property
in the properties, under the other tab as name, the name of
the sub's form is in the properties Data tab as Control
source.

That said,

me!child1.form![fieldname]
 
G

Guest

It seems to be working however when I try to enter a new customer name into
the subform I am having to problems.

1) I reveive a warning stating that states:
You can't assign a value to this object because
The Object may be a control on a read-only form
The object may be on a form that is open in design view
The value may be too large for this field

None of these are true as far as I can tell.

2) Once I have entered a new customer (despite the error above I am able to)
I cannot get the mainform to requery the Customer list and use the newly
added customer to the current file.

Below is the code I have tried to use:

Private Sub CustomerID_NotInList(NewData As String, Response As Integer)
Response = acDataErrContinue
If MsgBox("The party you have entered is not in the list. Would you like to
add it?", vbOKCancel) = vbOK Then
Me.customerID.Undo
Me.customerID.Value = Null
Me.subfrmcustomer.SetFocus
Me.subfrmcustomer.Form.DataEntry = True

End If
End Sub

Any suggestions?


Bob Quintal said:
=?Utf-8?B?Wm9sdGFyNTQ=?= <[email protected]>
wrote in
Just for clarification, would I then type:

me!subfrmCustomer.form![customerid] = newdata

so as to allow me to enter a new customer name and have that
added to the underlying tblCustomer table? (I have a number of
other fileds such as Name, Address etc.. for which, I assume
the same process would apply).
if subfrmCustomer is both the name of the subform control and
the name of the form in the control, yes. If the two are
different, use the name of the control, not the form

Bob Quintal said:
=?Utf-8?B?Wm9sdGFyNTQ=?= <[email protected]>
wrote in

Can someone tell me how to identify a field on a subform
using code? I am trying to create a routine that, when a
customer is entered into the main form and they are not in
the list, the subform will accept a new entry.

Currently I know that when specifying field names on a main
form I can simply type the field name or use
Me.[fieldname]. To refer to a subform can I use
subfrmName.[fieldname]?

Z

to refer to a control on the subform you have to reference
the subform control's name property which may not be the same
as the sub's form name. You will find the subform control's
name property
in the properties, under the other tab as name, the name of
the sub's form is in the properties Data tab as Control
source.

That said,

me!child1.form![fieldname]
 
B

Bob Quintal

=?Utf-8?B?Wm9sdGFyNTQ=?= <[email protected]>
wrote in
It seems to be working however when I try to enter a new
customer name into the subform I am having to problems.

1) I reveive a warning stating that states:
You can't assign a value to this object because
The Object may be a control on a read-only form
The object may be on a form that is open in design view
The value may be too large for this field

None of these are true as far as I can tell.

2) Once I have entered a new customer (despite the error above
I am able to) I cannot get the mainform to requery the
Customer list and use the newly added customer to the current
file.

Below is the code I have tried to use:

Private Sub CustomerID_NotInList(NewData As String, Response
As Integer)
Response = acDataErrContinue
If MsgBox("The party you have entered is not in the list.
Would you like to add it?", vbOKCancel) = vbOK Then
Me.customerID.Undo
Me.customerID.Value = Null
Me.subfrmcustomer.SetFocus
Me.subfrmcustomer.Form.DataEntry = True

End If
End Sub

Any suggestions?
I'm not sure about your error message.

If you pick an existing customer from the list do you get any
error message?

me.customer.undo and me.customerid,value = null seem to be
redundant. the Response = acDataErrContinue should take care of
that automatically.

I usually popup a small independent form to capture the data if
there are multiple fields to input, followed by setting the
Response to AcErrDataAdded which automatically requeries the
combobox.

see http://msdn2.microsoft.com/en-us/library/aa211431
(office.11).aspx




Bob Quintal said:
=?Utf-8?B?Wm9sdGFyNTQ=?= <[email protected]>
wrote in
Just for clarification, would I then type:

me!subfrmCustomer.form![customerid] = newdata

so as to allow me to enter a new customer name and have
that added to the underlying tblCustomer table? (I have a
number of other fileds such as Name, Address etc.. for
which, I assume the same process would apply).
if subfrmCustomer is both the name of the subform control and
the name of the form in the control, yes. If the two are
different, use the name of the control, not the form

:

=?Utf-8?B?Wm9sdGFyNTQ=?=

Can someone tell me how to identify a field on a subform
using code? I am trying to create a routine that, when
a customer is entered into the main form and they are
not in the list, the subform will accept a new entry.

Currently I know that when specifying field names on a
main form I can simply type the field name or use
Me.[fieldname]. To refer to a subform can I use
subfrmName.[fieldname]?

Z

to refer to a control on the subform you have to reference
the subform control's name property which may not be the
same as the sub's form name. You will find the subform
control's name property
in the properties, under the other tab as name, the name
of the sub's form is in the properties Data tab as Control
source.

That said,

me!child1.form![fieldname]
 

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