controlling a subform from main form? | | |
Hi,
I have 2 forms, frmretailorders, and frmretailorderline.
in the oncurrent of the main form, I check what the value of !status is. If
it is "complete", then i disable all text and combo boxes. However, I also
want to disable all of the same on the sub form. I do not know how to
reference the sub form :s
Current code:
----------------------------------------------
dim obj As Control
If status = 2 Or 3 Then
For Each obj In Me.Controls
If obj.ControlType = acTextBox Or obj.ControlType = acComboBox And
obj.Name <> "changestatus" Then
obj.Enabled = False
End If
Next
For Each obj In <REFER TO SUB FORM HERE>
If obj.ControlType = acTextBox Or obj.ControlType = acComboBox And
obj.Name <> "changestatus" Then
obj.Enabled = False
End If
Next
End If
End Sub
----------------------------------------------
The first IF works, but i need to get the second one working :)
if you can help, thanks in advance.
Craig | | | | re: controlling a subform from main form?
"Craig M" <NoSp@mPlz.Thx> wrote in message
news:408c2b8c$0$19421$cc9e4d1f@news-text.dial.pipex.com...[color=blue]
> Hi,
>
> I have 2 forms, frmretailorders, and frmretailorderline.
>
> in the oncurrent of the main form, I check what the value of !status is.[/color]
If[color=blue]
> it is "complete", then i disable all text and combo boxes. However, I also
> want to disable all of the same on the sub form. I do not know how to
> reference the sub form :s
>
> Current code:
> ----------------------------------------------
> dim obj As Control
>
> If status = 2 Or 3 Then
> For Each obj In Me.Controls
> If obj.ControlType = acTextBox Or obj.ControlType = acComboBox And
> obj.Name <> "changestatus" Then
> obj.Enabled = False
> End If
> Next
> For Each obj In <REFER TO SUB FORM HERE>
> If obj.ControlType = acTextBox Or obj.ControlType = acComboBox And
> obj.Name <> "changestatus" Then
> obj.Enabled = False
> End If
> Next
>
> End If
>
> End Sub
> ----------------------------------------------
>
> The first IF works, but i need to get the second one working :)
>
> if you can help, thanks in advance.
>
> Craig
>
>[/color]
Well, I managed to access the subform, but now, when I try and run it, the
loop hits the subform and says "You cannot disable a control while it has
the focus".
How can i work around this?
Craig | | | | re: controlling a subform from main form?
Craig M wrote:[color=blue]
> Hi,
>
> I have 2 forms, frmretailorders, and frmretailorderline.
>
> in the oncurrent of the main form, I check what the value of !status is. If
> it is "complete", then i disable all text and combo boxes. However, I also
> want to disable all of the same on the sub form. I do not know how to
> reference the sub form :s
>
> Current code:
> ----------------------------------------------
> dim obj As Control
>
> If status = 2 Or 3 Then
> For Each obj In Me.Controls
> If obj.ControlType = acTextBox Or obj.ControlType = acComboBox And
> obj.Name <> "changestatus" Then
> obj.Enabled = False
> End If
> Next
> For Each obj In <REFER TO SUB FORM HERE>
> If obj.ControlType = acTextBox Or obj.ControlType = acComboBox And
> obj.Name <> "changestatus" Then
> obj.Enabled = False
> End If
> Next
>
> End If
>
> End Sub
> ----------------------------------------------
>
> The first IF works, but i need to get the second one working :)
>
> if you can help, thanks in advance.
>
> Craig
>
>[/color]
Why don't you simly disable the subform instead of disabling all the
controls in the subform? Assuming your subform name is
frmretailorderline in the mainform then
Me.frmretailorderline.Enabled = (Me.status <> 2 And Me.Status <> 3)
will disaable if the status is not 2 or 3.
You can also lock the fields instead of disabling. If you lock
something you have to be aware that tho data can't be changed, if you
have an OnClick or OnDblClick event set that can fire. | | | | re: controlling a subform from main form?
"Salad" <oil@vinegar.com> wrote in message
news:oeYic.9323$eZ5.6595@newsread1.news.pas.earthl ink.net...[color=blue]
> Craig M wrote:[color=green]
> > Hi,
> >
> > I have 2 forms, frmretailorders, and frmretailorderline.
> >
> > in the oncurrent of the main form, I check what the value of !status is.[/color][/color]
If[color=blue][color=green]
> > it is "complete", then i disable all text and combo boxes. However, I[/color][/color]
also[color=blue][color=green]
> > want to disable all of the same on the sub form. I do not know how to
> > reference the sub form :s
> >
> > Current code:
> > ----------------------------------------------
> > dim obj As Control
> >
> > If status = 2 Or 3 Then
> > For Each obj In Me.Controls
> > If obj.ControlType = acTextBox Or obj.ControlType = acComboBox And
> > obj.Name <> "changestatus" Then
> > obj.Enabled = False
> > End If
> > Next
> > For Each obj In <REFER TO SUB FORM HERE>
> > If obj.ControlType = acTextBox Or obj.ControlType = acComboBox And
> > obj.Name <> "changestatus" Then
> > obj.Enabled = False
> > End If
> > Next
> >
> > End If
> >
> > End Sub
> > ----------------------------------------------
> >
> > The first IF works, but i need to get the second one working :)
> >
> > if you can help, thanks in advance.
> >
> > Craig
> >
> >[/color]
> Why don't you simly disable the subform instead of disabling all the
> controls in the subform? Assuming your subform name is
> frmretailorderline in the mainform then
>
> Me.frmretailorderline.Enabled = (Me.status <> 2 And Me.Status <> 3)
>
> will disaable if the status is not 2 or 3.
>
> You can also lock the fields instead of disabling. If you lock
> something you have to be aware that tho data can't be changed, if you
> have an OnClick or OnDblClick event set that can fire.
>[/color]
Ahh, great!
I ended up locking all of the fields, and changing the BG color, heh.
Thanks for the info, I will try it in a few.
Craig | | | | re: controlling a subform from main form?
Craig M wrote:
[color=blue]
> "Salad" <oil@vinegar.com> wrote in message
> news:oeYic.9323$eZ5.6595@newsread1.news.pas.earthl ink.net...
>[color=green]
>>Craig M wrote:
>>[color=darkred]
>>>Hi,
>>>
>>>I have 2 forms, frmretailorders, and frmretailorderline.
>>>
>>>in the oncurrent of the main form, I check what the value of !status is.[/color][/color]
>
> If
>[color=green][color=darkred]
>>>it is "complete", then i disable all text and combo boxes. However, I[/color][/color]
>
> also
>[color=green][color=darkred]
>>>want to disable all of the same on the sub form. I do not know how to
>>>reference the sub form :s
>>>
>>>Current code:
>>>----------------------------------------------
>>>dim obj As Control
>>>
>>>If status = 2 Or 3 Then
>>>For Each obj In Me.Controls
>>> If obj.ControlType = acTextBox Or obj.ControlType = acComboBox And
>>>obj.Name <> "changestatus" Then
>>> obj.Enabled = False
>>> End If
>>>Next
>>>For Each obj In <REFER TO SUB FORM HERE>
>>> If obj.ControlType = acTextBox Or obj.ControlType = acComboBox And
>>>obj.Name <> "changestatus" Then
>>> obj.Enabled = False
>>> End If
>>>Next
>>>
>>>End If
>>>
>>>End Sub
>>>----------------------------------------------
>>>
>>>The first IF works, but i need to get the second one working :)
>>>
>>>if you can help, thanks in advance.
>>>
>>>Craig
>>>
>>>[/color]
>>
>>Why don't you simly disable the subform instead of disabling all the
>>controls in the subform? Assuming your subform name is
>>frmretailorderline in the mainform then
>>
>>Me.frmretailorderline.Enabled = (Me.status <> 2 And Me.Status <> 3)
>>
>>will disaable if the status is not 2 or 3.
>>
>>You can also lock the fields instead of disabling. If you lock
>>something you have to be aware that tho data can't be changed, if you
>>have an OnClick or OnDblClick event set that can fire.
>>[/color]
>
>
> Ahh, great!
>
> I ended up locking all of the fields, and changing the BG color, heh.
>
> Thanks for the info, I will try it in a few.
>
> Craig
>
>[/color]
Try this.
Create a temp form and drag a few text boxes on the form. Set the following
Enable Locked
True False
True True
False True
False False
Then open the form. The background changes depending on the enable/lock
status.
You could do something like this
blnEnable = True
Me.Text0.Enable = blnEnable
Me.Text0.Locked = Not blnEnable
So if you did want to cycle through a control list you can come up with
an effect that suits you and the users. |  | 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,449 network members.
|