Subform reference

P

Pwyd

The main form
[Main Record]
has on it a subform named LineItemSubformQuery

if i want to change the subform's enabled property from an afterupdate
property of a field on the main form, how do i reference that?

i'd also like to change the subform's line's to be colored light gray, as if
grayed out, because apparently unlike other controls that are not enabled,
its color does not change when its not enabled.

Help please?
 
M

Marshall Barton

Pwyd said:
The main form
[Main Record]
has on it a subform named LineItemSubformQuery

if i want to change the subform's enabled property from an afterupdate
property of a field on the main form, how do i reference that?

i'd also like to change the subform's line's to be colored light gray, as if
grayed out, because apparently unlike other controls that are not enabled,
its color does not change when its not enabled.


With Me.subformcontrolname
.Form.linecontrol1.BorderColor = -2147483633
.Form.linecontrol2.BorderColor = -2147483633
.Form.linecontrol3.BorderColor = -2147483633
.Enabled = False
End With
 
P

Pwyd

This reference will apply both from the main form and any subform
control,macro, etc, that calls it?

Marshall Barton said:
Pwyd said:
The main form
[Main Record]
has on it a subform named LineItemSubformQuery

if i want to change the subform's enabled property from an afterupdate
property of a field on the main form, how do i reference that?

i'd also like to change the subform's line's to be colored light gray, as if
grayed out, because apparently unlike other controls that are not enabled,
its color does not change when its not enabled.


With Me.subformcontrolname
.Form.linecontrol1.BorderColor = -2147483633
.Form.linecontrol2.BorderColor = -2147483633
.Form.linecontrol3.BorderColor = -2147483633
.Enabled = False
End With
 
P

Pwyd

I'm sorry this doesn't work at all. It gives me invalid reference to object
or function name.


i tried playing with it a little bit but i can't get it to work at all.



Pwyd said:
This reference will apply both from the main form and any subform
control,macro, etc, that calls it?

Marshall Barton said:
Pwyd said:
The main form
[Main Record]
has on it a subform named LineItemSubformQuery

if i want to change the subform's enabled property from an afterupdate
property of a field on the main form, how do i reference that?

i'd also like to change the subform's line's to be colored light gray, as if
grayed out, because apparently unlike other controls that are not enabled,
its color does not change when its not enabled.


With Me.subformcontrolname
.Form.linecontrol1.BorderColor = -2147483633
.Form.linecontrol2.BorderColor = -2147483633
.Form.linecontrol3.BorderColor = -2147483633
.Enabled = False
End With
 
M

Marshall Barton

No, that code does what you asked when it's in a main form
control's AfterUpdate event.

If you want to "call it" from other forms/subforms, then I
recommend that you create a Public Sub procedure in your
main form's module:

Public Sub DoMyThing()
' put the code here
. . .
End Sub

Then any subform can call it using:
Parent.DoMyThing

And a main form control's AfterUpdate event would just use:
DoMyThing

Not that you asked, but, when the main form is open, you
could also call it from any other form using:
Forms![the main form].DoMyThing
--
Marsh
MVP [MS Access]


This reference will apply both from the main form and any subform
control,macro, etc, that calls it?

Marshall Barton said:
Pwyd said:
The main form
[Main Record]
has on it a subform named LineItemSubformQuery

if i want to change the subform's enabled property from an afterupdate
property of a field on the main form, how do i reference that?

i'd also like to change the subform's line's to be colored light gray, as if
grayed out, because apparently unlike other controls that are not enabled,
its color does not change when its not enabled.


With Me.subformcontrolname
.Form.linecontrol1.BorderColor = -2147483633
.Form.linecontrol2.BorderColor = -2147483633
.Form.linecontrol3.BorderColor = -2147483633
.Enabled = False
End With
 
P

Pwyd

Ah. then perhaps i've asked the wrong question. Its in one of the main
form's field's afterupdate. not hte form itself's afterupdate.


Marshall Barton said:
No, that code does what you asked when it's in a main form
control's AfterUpdate event.

If you want to "call it" from other forms/subforms, then I
recommend that you create a Public Sub procedure in your
main form's module:

Public Sub DoMyThing()
' put the code here
. . .
End Sub

Then any subform can call it using:
Parent.DoMyThing

And a main form control's AfterUpdate event would just use:
DoMyThing

Not that you asked, but, when the main form is open, you
could also call it from any other form using:
Forms![the main form].DoMyThing
--
Marsh
MVP [MS Access]


This reference will apply both from the main form and any subform
control,macro, etc, that calls it?

Marshall Barton said:
Pwyd wrote:
The main form
[Main Record]
has on it a subform named LineItemSubformQuery

if i want to change the subform's enabled property from an afterupdate
property of a field on the main form, how do i reference that?

i'd also like to change the subform's line's to be colored light gray, as if
grayed out, because apparently unlike other controls that are not enabled,
its color does not change when its not enabled.


With Me.subformcontrolname
.Form.linecontrol1.BorderColor = -2147483633
.Form.linecontrol2.BorderColor = -2147483633
.Form.linecontrol3.BorderColor = -2147483633
.Enabled = False
End With
 
M

Marshall Barton

How can I tell what you tried without seeing a Copy/Paste of
the relevant code procedures along with the names of your
controls? At this point, all I can do is guess that you
probably did not change the control names I used to the
names you actually have on your form.
--
Marsh
MVP [MS Access]
I'm sorry this doesn't work at all. It gives me invalid reference to object
or function name.

i tried playing with it a little bit but i can't get it to work at all.


Pwyd said:
This reference will apply both from the main form and any subform
control,macro, etc, that calls it?

Marshall Barton said:
Pwyd wrote:
The main form
[Main Record]
has on it a subform named LineItemSubformQuery

if i want to change the subform's enabled property from an afterupdate
property of a field on the main form, how do i reference that?

i'd also like to change the subform's line's to be colored light gray, as if
grayed out, because apparently unlike other controls that are not enabled,
its color does not change when its not enabled.


With Me.subformcontrolname
.Form.linecontrol1.BorderColor = -2147483633
.Form.linecontrol2.BorderColor = -2147483633
.Form.linecontrol3.BorderColor = -2147483633
.Enabled = False
End With
 
M

Marshall Barton

Doesn't matter. Call the public procedure from wherever you
want using the appropriate object reference.

If you are going to call the code from anywhere besides the
main form field's AfterUpdate event, I do not recommend
leaving it in the AfterUpdate event. Somewhere down the
road you may need to add more code to the AfterUpdate event
and probably don't want the new code getting involved when
the other places want to disable the combo box, etc.
--
Marsh
MVP [MS Access]

Ah. then perhaps i've asked the wrong question. Its in one of the main
form's field's afterupdate. not hte form itself's afterupdate.


Marshall Barton said:
No, that code does what you asked when it's in a main form
control's AfterUpdate event.

If you want to "call it" from other forms/subforms, then I
recommend that you create a Public Sub procedure in your
main form's module:

Public Sub DoMyThing()
' put the code here
. . .
End Sub

Then any subform can call it using:
Parent.DoMyThing

And a main form control's AfterUpdate event would just use:
DoMyThing

Not that you asked, but, when the main form is open, you
could also call it from any other form using:
Forms![the main form].DoMyThing

This reference will apply both from the main form and any subform
control,macro, etc, that calls it?

:

Pwyd wrote:
The main form
[Main Record]
has on it a subform named LineItemSubformQuery

if i want to change the subform's enabled property from an afterupdate
property of a field on the main form, how do i reference that?

i'd also like to change the subform's line's to be colored light gray, as if
grayed out, because apparently unlike other controls that are not enabled,
its color does not change when its not enabled.


With Me.subformcontrolname
.Form.linecontrol1.BorderColor = -2147483633
.Form.linecontrol2.BorderColor = -2147483633
.Form.linecontrol3.BorderColor = -2147483633
.Enabled = False
End With
 
P

Pwyd

There are no speed or other qualities that are degraded by using the form
afterupdate instead of a specific control's afterupdate?

Marshall Barton said:
Doesn't matter. Call the public procedure from wherever you
want using the appropriate object reference.

If you are going to call the code from anywhere besides the
main form field's AfterUpdate event, I do not recommend
leaving it in the AfterUpdate event. Somewhere down the
road you may need to add more code to the AfterUpdate event
and probably don't want the new code getting involved when
the other places want to disable the combo box, etc.
--
Marsh
MVP [MS Access]

Ah. then perhaps i've asked the wrong question. Its in one of the main
form's field's afterupdate. not hte form itself's afterupdate.


Marshall Barton said:
No, that code does what you asked when it's in a main form
control's AfterUpdate event.

If you want to "call it" from other forms/subforms, then I
recommend that you create a Public Sub procedure in your
main form's module:

Public Sub DoMyThing()
' put the code here
. . .
End Sub

Then any subform can call it using:
Parent.DoMyThing

And a main form control's AfterUpdate event would just use:
DoMyThing

Not that you asked, but, when the main form is open, you
could also call it from any other form using:
Forms![the main form].DoMyThing


Pwyd wrote:
This reference will apply both from the main form and any subform
control,macro, etc, that calls it?

:

Pwyd wrote:
The main form
[Main Record]
has on it a subform named LineItemSubformQuery

if i want to change the subform's enabled property from an afterupdate
property of a field on the main form, how do i reference that?

i'd also like to change the subform's line's to be colored light gray, as if
grayed out, because apparently unlike other controls that are not enabled,
its color does not change when its not enabled.


With Me.subformcontrolname
.Form.linecontrol1.BorderColor = -2147483633
.Form.linecontrol2.BorderColor = -2147483633
.Form.linecontrol3.BorderColor = -2147483633
.Enabled = False
End With
 
M

Marshall Barton

Whoa, hold on there. How did you get the idea that the form
event was being discussed? I never said anything about the
form's AfterUpdate event.

There's nothing against it, it just that the form's
AfterUpdate event serves a very different purpose than a
control's AfterUpdate event. Because they are used for
different things, performance doesn't enter into the
discussion (and besides, the performace of the events would
be about the same).

Use the form event when you need to do something after a
record has been saved. Use a control's event to do
something after the control's Value has been entered/edited.
For your purposes, you should be using the combo box's
AfterUpdate event and, possibly the form's Current event.
--
Marsh
MVP [MS Access]

There are no speed or other qualities that are degraded by using the form
afterupdate instead of a specific control's afterupdate?

Marshall Barton said:
Doesn't matter. Call the public procedure from wherever you
want using the appropriate object reference.

If you are going to call the code from anywhere besides the
main form field's AfterUpdate event, I do not recommend
leaving it in the AfterUpdate event. Somewhere down the
road you may need to add more code to the AfterUpdate event
and probably don't want the new code getting involved when
the other places want to disable the combo box, etc.

Ah. then perhaps i've asked the wrong question. Its in one of the main
form's field's afterupdate. not hte form itself's afterupdate.


:

No, that code does what you asked when it's in a main form
control's AfterUpdate event.

If you want to "call it" from other forms/subforms, then I
recommend that you create a Public Sub procedure in your
main form's module:

Public Sub DoMyThing()
' put the code here
. . .
End Sub

Then any subform can call it using:
Parent.DoMyThing

And a main form control's AfterUpdate event would just use:
DoMyThing

Not that you asked, but, when the main form is open, you
could also call it from any other form using:
Forms![the main form].DoMyThing


Pwyd wrote:
This reference will apply both from the main form and any subform
control,macro, etc, that calls it?

:

Pwyd wrote:
The main form
[Main Record]
has on it a subform named LineItemSubformQuery

if i want to change the subform's enabled property from an afterupdate
property of a field on the main form, how do i reference that?

i'd also like to change the subform's line's to be colored light gray, as if
grayed out, because apparently unlike other controls that are not enabled,
its color does not change when its not enabled.


With Me.subformcontrolname
.Form.linecontrol1.BorderColor = -2147483633
.Form.linecontrol2.BorderColor = -2147483633
.Form.linecontrol3.BorderColor = -2147483633
.Enabled = False
End With
 
P

Pwyd

apparently i misread where yo uwrote main form FIELD....

anyway. so i have this

Private Sub V_InvoiceNumber_AfterUpdate()
If Not (IsNull([V_InvoiceNumber])) Then
With Me.LineItemSubFormQuery_subform
.linecontrol1.BorderColor = -2147483633
.linecontrol2.BorderColor = -2147483633
.linecontrol3.BorderColor = -2147483633
.Enabled = True
End With
ElseIf (IsNull([V_InvoiceNumber])) Then
With Me.LineItemSubFormQuery_subform
.linecontrol1.BorderColor = 16777215
.linecontrol2.BorderColor = 16777215
.linecontrol3.BorderColor = 16777215
.Enabled = False
End With
End If

End Sub



but its actually grumbling about "linecontrol" as not a member or method.

Marshall Barton said:
Whoa, hold on there. How did you get the idea that the form
event was being discussed? I never said anything about the
form's AfterUpdate event.

There's nothing against it, it just that the form's
AfterUpdate event serves a very different purpose than a
control's AfterUpdate event. Because they are used for
different things, performance doesn't enter into the
discussion (and besides, the performace of the events would
be about the same).

Use the form event when you need to do something after a
record has been saved. Use a control's event to do
something after the control's Value has been entered/edited.
For your purposes, you should be using the combo box's
AfterUpdate event and, possibly the form's Current event.
--
Marsh
MVP [MS Access]

There are no speed or other qualities that are degraded by using the form
afterupdate instead of a specific control's afterupdate?

Marshall Barton said:
Doesn't matter. Call the public procedure from wherever you
want using the appropriate object reference.

If you are going to call the code from anywhere besides the
main form field's AfterUpdate event, I do not recommend
leaving it in the AfterUpdate event. Somewhere down the
road you may need to add more code to the AfterUpdate event
and probably don't want the new code getting involved when
the other places want to disable the combo box, etc.


Pwyd wrote:
Ah. then perhaps i've asked the wrong question. Its in one of the main
form's field's afterupdate. not hte form itself's afterupdate.


:

No, that code does what you asked when it's in a main form
control's AfterUpdate event.

If you want to "call it" from other forms/subforms, then I
recommend that you create a Public Sub procedure in your
main form's module:

Public Sub DoMyThing()
' put the code here
. . .
End Sub

Then any subform can call it using:
Parent.DoMyThing

And a main form control's AfterUpdate event would just use:
DoMyThing

Not that you asked, but, when the main form is open, you
could also call it from any other form using:
Forms![the main form].DoMyThing


Pwyd wrote:
This reference will apply both from the main form and any subform
control,macro, etc, that calls it?

:

Pwyd wrote:
The main form
[Main Record]
has on it a subform named LineItemSubformQuery

if i want to change the subform's enabled property from an afterupdate
property of a field on the main form, how do i reference that?

i'd also like to change the subform's line's to be colored light gray, as if
grayed out, because apparently unlike other controls that are not enabled,
its color does not change when its not enabled.


With Me.subformcontrolname
.Form.linecontrol1.BorderColor = -2147483633
.Form.linecontrol2.BorderColor = -2147483633
.Form.linecontrol3.BorderColor = -2147483633
.Enabled = False
End With
 
M

Marshall Barton

Pwyd said:
apparently i misread where yo uwrote main form FIELD....

anyway. so i have this

Private Sub V_InvoiceNumber_AfterUpdate()
If Not (IsNull([V_InvoiceNumber])) Then
With Me.LineItemSubFormQuery_subform
.linecontrol1.BorderColor = -2147483633
.linecontrol2.BorderColor = -2147483633
.linecontrol3.BorderColor = -2147483633
.Enabled = True
End With
ElseIf (IsNull([V_InvoiceNumber])) Then
With Me.LineItemSubFormQuery_subform
.linecontrol1.BorderColor = 16777215
.linecontrol2.BorderColor = 16777215
.linecontrol3.BorderColor = 16777215
.Enabled = False
End With
End If

End Sub

but its actually grumbling about "linecontrol" as not a member or method.


Well, since you never did say what the names of your line
controls are, I just made up some names that you were
supposed to replace with the real control names.
 
P

Pwyd

oh :0 i've never worked with line controls.

I'm not even familiar with the term. let me look it up.

Hrm. that wasn't very helpful.

I was just trying to "disable" the entire subform from editing.
Marshall Barton said:
Pwyd said:
apparently i misread where yo uwrote main form FIELD....

anyway. so i have this

Private Sub V_InvoiceNumber_AfterUpdate()
If Not (IsNull([V_InvoiceNumber])) Then
With Me.LineItemSubFormQuery_subform
.linecontrol1.BorderColor = -2147483633
.linecontrol2.BorderColor = -2147483633
.linecontrol3.BorderColor = -2147483633
.Enabled = True
End With
ElseIf (IsNull([V_InvoiceNumber])) Then
With Me.LineItemSubFormQuery_subform
.linecontrol1.BorderColor = 16777215
.linecontrol2.BorderColor = 16777215
.linecontrol3.BorderColor = 16777215
.Enabled = False
End With
End If

End Sub

but its actually grumbling about "linecontrol" as not a member or method.


Well, since you never did say what the names of your line
controls are, I just made up some names that you were
supposed to replace with the real control names.
 
M

Marshall Barton

I guess I misunderstood what you meant by:
"change the subform's line's
to be colored light gray"
You might have meant that you want the detail section's
controls to look like they are disabled. While the line of
code:
.Enabled = False
makes it imposible for users to interact with the data in
the subform, it does not change the appearance. To do that
you should disable all of the individual data controls in
the subform. This can be done by replacing the code for
linecontrols with something like this air code:

Dim ctl As Controls
On Error Resume Next 'ignore controls without Enabled
For Each ctl In .Form.Controls
ctl.Enabled = False
Next ctl
--
Marsh
MVP [MS Access]

oh :0 i've never worked with line controls.

I'm not even familiar with the term. let me look it up.

Hrm. that wasn't very helpful.

I was just trying to "disable" the entire subform from editing.
Marshall Barton said:
Pwyd said:
apparently i misread where yo uwrote main form FIELD....

anyway. so i have this

Private Sub V_InvoiceNumber_AfterUpdate()
If Not (IsNull([V_InvoiceNumber])) Then
With Me.LineItemSubFormQuery_subform
.linecontrol1.BorderColor = -2147483633
.linecontrol2.BorderColor = -2147483633
.linecontrol3.BorderColor = -2147483633
.Enabled = True
End With
ElseIf (IsNull([V_InvoiceNumber])) Then
With Me.LineItemSubFormQuery_subform
.linecontrol1.BorderColor = 16777215
.linecontrol2.BorderColor = 16777215
.linecontrol3.BorderColor = 16777215
.Enabled = False
End With
End If

End Sub

but its actually grumbling about "linecontrol" as not a member or method.


Well, since you never did say what the names of your line
controls are, I just made up some names that you were
supposed to replace with the real control names.
 
P

Pwyd

That's precisely what i meant, thank you very much Marshall, for your help
and informed explanation. I will definitely use this.

Marshall Barton said:
I guess I misunderstood what you meant by:
"change the subform's line's
to be colored light gray"
You might have meant that you want the detail section's
controls to look like they are disabled. While the line of
code:
.Enabled = False
makes it imposible for users to interact with the data in
the subform, it does not change the appearance. To do that
you should disable all of the individual data controls in
the subform. This can be done by replacing the code for
linecontrols with something like this air code:

Dim ctl As Controls
On Error Resume Next 'ignore controls without Enabled
For Each ctl In .Form.Controls
ctl.Enabled = False
Next ctl
--
Marsh
MVP [MS Access]

oh :0 i've never worked with line controls.

I'm not even familiar with the term. let me look it up.

Hrm. that wasn't very helpful.

I was just trying to "disable" the entire subform from editing.
Marshall Barton said:
Pwyd wrote:
apparently i misread where yo uwrote main form FIELD....

anyway. so i have this

Private Sub V_InvoiceNumber_AfterUpdate()
If Not (IsNull([V_InvoiceNumber])) Then
With Me.LineItemSubFormQuery_subform
.linecontrol1.BorderColor = -2147483633
.linecontrol2.BorderColor = -2147483633
.linecontrol3.BorderColor = -2147483633
.Enabled = True
End With
ElseIf (IsNull([V_InvoiceNumber])) Then
With Me.LineItemSubFormQuery_subform
.linecontrol1.BorderColor = 16777215
.linecontrol2.BorderColor = 16777215
.linecontrol3.BorderColor = 16777215
.Enabled = False
End With
End If

End Sub

but its actually grumbling about "linecontrol" as not a member or method.


Well, since you never did say what the names of your line
controls are, I just made up some names that you were
supposed to replace with the real control names.
 
P

Pwyd

hrm. it doesn't like "ctl.Enabled" .... or are you using a shorthand again?
because i wouldn't know what control woudl go in there except like acSubform.

i moved it to "on current" for the main form as you suggested, as i see the
logic of that placement. Should i also default the subform to enabled =
false then, so that new records start that way?

Marshall Barton said:
I guess I misunderstood what you meant by:
"change the subform's line's
to be colored light gray"
You might have meant that you want the detail section's
controls to look like they are disabled. While the line of
code:
.Enabled = False
makes it imposible for users to interact with the data in
the subform, it does not change the appearance. To do that
you should disable all of the individual data controls in
the subform. This can be done by replacing the code for
linecontrols with something like this air code:

Dim ctl As Controls
On Error Resume Next 'ignore controls without Enabled
For Each ctl In .Form.Controls
ctl.Enabled = False
Next ctl
--
Marsh
MVP [MS Access]

oh :0 i've never worked with line controls.

I'm not even familiar with the term. let me look it up.

Hrm. that wasn't very helpful.

I was just trying to "disable" the entire subform from editing.
Marshall Barton said:
Pwyd wrote:
apparently i misread where yo uwrote main form FIELD....

anyway. so i have this

Private Sub V_InvoiceNumber_AfterUpdate()
If Not (IsNull([V_InvoiceNumber])) Then
With Me.LineItemSubFormQuery_subform
.linecontrol1.BorderColor = -2147483633
.linecontrol2.BorderColor = -2147483633
.linecontrol3.BorderColor = -2147483633
.Enabled = True
End With
ElseIf (IsNull([V_InvoiceNumber])) Then
With Me.LineItemSubFormQuery_subform
.linecontrol1.BorderColor = 16777215
.linecontrol2.BorderColor = 16777215
.linecontrol3.BorderColor = 16777215
.Enabled = False
End With
End If

End Sub

but its actually grumbling about "linecontrol" as not a member or method.


Well, since you never did say what the names of your line
controls are, I just made up some names that you were
supposed to replace with the real control names.
 
M

Marshall Barton

I fat fingered another one. It's supposed to be

Dim ctl As Control

without the s on the end.
--
Marsh
MVP [MS Access]

hrm. it doesn't like "ctl.Enabled" .... or are you using a shorthand again?
because i wouldn't know what control woudl go in there except like acSubform.

i moved it to "on current" for the main form as you suggested, as i see the
logic of that placement. Should i also default the subform to enabled =
false then, so that new records start that way?

Marshall Barton said:
I guess I misunderstood what you meant by:
"change the subform's line's
to be colored light gray"
You might have meant that you want the detail section's
controls to look like they are disabled. While the line of
code:
.Enabled = False
makes it imposible for users to interact with the data in
the subform, it does not change the appearance. To do that
you should disable all of the individual data controls in
the subform. This can be done by replacing the code for
linecontrols with something like this air code:

Dim ctl As Controls
On Error Resume Next 'ignore controls without Enabled
For Each ctl In .Form.Controls
ctl.Enabled = False
Next ctl

oh :0 i've never worked with line controls.

I'm not even familiar with the term. let me look it up.

Hrm. that wasn't very helpful.

I was just trying to "disable" the entire subform from editing.
:

Pwyd wrote:
apparently i misread where yo uwrote main form FIELD....

anyway. so i have this

Private Sub V_InvoiceNumber_AfterUpdate()
If Not (IsNull([V_InvoiceNumber])) Then
With Me.LineItemSubFormQuery_subform
.linecontrol1.BorderColor = -2147483633
.linecontrol2.BorderColor = -2147483633
.linecontrol3.BorderColor = -2147483633
.Enabled = True
End With
ElseIf (IsNull([V_InvoiceNumber])) Then
With Me.LineItemSubFormQuery_subform
.linecontrol1.BorderColor = 16777215
.linecontrol2.BorderColor = 16777215
.linecontrol3.BorderColor = 16777215
.Enabled = False
End With
End If

End Sub

but its actually grumbling about "linecontrol" as not a member or method.


Well, since you never did say what the names of your line
controls are, I just made up some names that you were
supposed to replace with the real control names.
 
P

Pwyd

thank you marshall. Let me ask you another question while i've got you here.
I've heard it said that the subform renders before a main form. Does this
also mean the data associated with it is also rendered first? If i have a
new record, and a piece of information in the subform is base on a piece of
information on the main form, would the subform state an error if it tried to
get that bit of data? or would it just fail to appear?



Marshall Barton said:
I fat fingered another one. It's supposed to be

Dim ctl As Control

without the s on the end.
--
Marsh
MVP [MS Access]

hrm. it doesn't like "ctl.Enabled" .... or are you using a shorthand again?
because i wouldn't know what control woudl go in there except like acSubform.

i moved it to "on current" for the main form as you suggested, as i see the
logic of that placement. Should i also default the subform to enabled =
false then, so that new records start that way?

Marshall Barton said:
I guess I misunderstood what you meant by:
"change the subform's line's
to be colored light gray"
You might have meant that you want the detail section's
controls to look like they are disabled. While the line of
code:
.Enabled = False
makes it imposible for users to interact with the data in
the subform, it does not change the appearance. To do that
you should disable all of the individual data controls in
the subform. This can be done by replacing the code for
linecontrols with something like this air code:

Dim ctl As Controls
On Error Resume Next 'ignore controls without Enabled
For Each ctl In .Form.Controls
ctl.Enabled = False
Next ctl


Pwyd wrote:
oh :0 i've never worked with line controls.

I'm not even familiar with the term. let me look it up.

Hrm. that wasn't very helpful.

I was just trying to "disable" the entire subform from editing.
:

Pwyd wrote:
apparently i misread where yo uwrote main form FIELD....

anyway. so i have this

Private Sub V_InvoiceNumber_AfterUpdate()
If Not (IsNull([V_InvoiceNumber])) Then
With Me.LineItemSubFormQuery_subform
.linecontrol1.BorderColor = -2147483633
.linecontrol2.BorderColor = -2147483633
.linecontrol3.BorderColor = -2147483633
.Enabled = True
End With
ElseIf (IsNull([V_InvoiceNumber])) Then
With Me.LineItemSubFormQuery_subform
.linecontrol1.BorderColor = 16777215
.linecontrol2.BorderColor = 16777215
.linecontrol3.BorderColor = 16777215
.Enabled = False
End With
End If

End Sub

but its actually grumbling about "linecontrol" as not a member or method.


Well, since you never did say what the names of your line
controls are, I just made up some names that you were
supposed to replace with the real control names.
 
M

Marshall Barton

Pwyd said:
thank you marshall. Let me ask you another question while i've got you here.
I've heard it said that the subform renders before a main form. Does this
also mean the data associated with it is also rendered first? If i have a
new record, and a piece of information in the subform is base on a piece of
information on the main form, would the subform state an error if it tried to
get that bit of data? or would it just fail to appear?


The word "render" means to draw a form, its controls and
display the values. I don't know when stuff is rendered,
but the form is painted/rendered at a lower priority than
everything else so I would expect that the order that things
are painted doesn't really matter because most everthing
else is done before that.

OTOH, I suspect that you are really asking about when the
data is loaded/calculated and, yes subform's are loaded
before the main form (unlike subreports). But, I'm fairly
sure that subforms are requeried/recalculated/repainted
after the main form is loaded (at least the Link
Master/Child properties require all that). So a subfom
control epression that references a main form value should
end up being ok. Try it and see what happens.

BUT, since VBA code executes at the higest priority, any
subform code that tries to reference a main form control
will error until after the main form is loaded.

If you are really curious, add a Debug.Print statement to
the main form and subform Open, Load and Current events.
Then you can look at the Immediate window to see the order
and how many times the events happen. You could even create
a Public function in a standard module and add it to a
control expression to see when the control is recalculated:

Public Function Debugging(mymsg As String, retval)
Debug.Print mymsg
Debugging = retval
End Function

Then a control expression like =Parent.textbox could be
temporarily modified to:
For a number type main form value:
=Parent.textbox+Debugging("subform control A", 0)
Or, for a mainform text box with a string value:
=Parent.textbox+Debugging("subform control B", "")

Play around with stuff like that when you have an issue of
when/what Access is doing whatever.
 
P

Pwyd

Okay but if that occurs, it will post an error, it won't just ignore it and
keep on running as an internal error and not post it to the user.
 

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