Form group invisible by field criteria

M

MikeF

Have a group of fields on a form, running beside each other, that adjust
their respective local currency amounts into US Dollars.

On numerous occasions the local currency is indeed US Dollars, so the
redundant group of US Dollar fields does not need to be visible.

How can I make that group if fields invisible "IF" [LocalCurrency] = "USD"
??

Regards,
- Mike
 
D

dymondjack

I'm thinking this may be done using the OnCurrent event. Check the value of
LocalCurrency and if it equals "USD" then hide the other controls:


Private Sub Form_Current()

If Nz(Me.LocalCurrency, "") = "USD" Then
'Hide Controls
Me.control1.Visible = False
Me.control2.Visible = False
Else
'Show Controls
Me.control1.Visible = True
Me.control2.Visible = True
End If

End Sub




When working with a large group of controls, you can create a collection to
save you from having to hardcode each control. However, I'm not experianced
enough with this to give any advice other than it can be done...


hth



End Sub

--
Jack Leach
www.tristatemachine.com

- "Success is the ability to go from one failure to another with no loss of
enthusiasm." - Sir Winston Churchill
 
M

MikeF

Thanx for the reply.

Tried this code, but it only hides the "rectangle" that surrounds the fields.
I actually wanted to *group* the fields, and hide that control only.
The end result being that everything would be hidden.

Any ideas, or do I have to pick thru each control?

Thanx again,
- Mike

dymondjack said:
I'm thinking this may be done using the OnCurrent event. Check the value of
LocalCurrency and if it equals "USD" then hide the other controls:


Private Sub Form_Current()

If Nz(Me.LocalCurrency, "") = "USD" Then
'Hide Controls
Me.control1.Visible = False
Me.control2.Visible = False
Else
'Show Controls
Me.control1.Visible = True
Me.control2.Visible = True
End If

End Sub




When working with a large group of controls, you can create a collection to
save you from having to hardcode each control. However, I'm not experianced
enough with this to give any advice other than it can be done...


hth



End Sub

--
Jack Leach
www.tristatemachine.com

- "Success is the ability to go from one failure to another with no loss of
enthusiasm." - Sir Winston Churchill


MikeF said:
Have a group of fields on a form, running beside each other, that adjust
their respective local currency amounts into US Dollars.

On numerous occasions the local currency is indeed US Dollars, so the
redundant group of US Dollar fields does not need to be visible.

How can I make that group if fields invisible "IF" [LocalCurrency] = "USD"
??

Regards,
- Mike
 
J

JimBurke via AccessMonster.com

I could be wrong, but I don't think there's a way to do that in Access. In VB.
Net and other apps I believe you can define something as a container, and
then set it's visible property, but I don't think Access has an equivalent
concept. I;m still using 2000, so maybe newer versions do?

What I do in one my apps is I define a label that is big enough to cover the
controls I don't want seen (I have a HUGE number of them - I wouldn't bother
if it was a relatively small number, then I'd just set the indivisual control
visible properties). I set it's Back Style property to Normal and it's Back
Color to the same as that of the form and place it over the controls. Then I
set it's visible property. If it's visible then those other controls aren't
because the label is over them. It can be a little bit messy when you have
to edit the form, because you have to move it around when you need to get to
the covered controls, but it works.
Thanx for the reply.

Tried this code, but it only hides the "rectangle" that surrounds the fields.
I actually wanted to *group* the fields, and hide that control only.
The end result being that everything would be hidden.

Any ideas, or do I have to pick thru each control?

Thanx again,
- Mike
I'm thinking this may be done using the OnCurrent event. Check the value of
LocalCurrency and if it equals "USD" then hide the other controls:
[quoted text clipped - 32 lines]
 
M

MikeF

Simplistically brilliant !!
Thanx Jim, that sounds like the solution.

- Mike

JimBurke via AccessMonster.com said:
I could be wrong, but I don't think there's a way to do that in Access. In VB.
Net and other apps I believe you can define something as a container, and
then set it's visible property, but I don't think Access has an equivalent
concept. I;m still using 2000, so maybe newer versions do?

What I do in one my apps is I define a label that is big enough to cover the
controls I don't want seen (I have a HUGE number of them - I wouldn't bother
if it was a relatively small number, then I'd just set the indivisual control
visible properties). I set it's Back Style property to Normal and it's Back
Color to the same as that of the form and place it over the controls. Then I
set it's visible property. If it's visible then those other controls aren't
because the label is over them. It can be a little bit messy when you have
to edit the form, because you have to move it around when you need to get to
the covered controls, but it works.
Thanx for the reply.

Tried this code, but it only hides the "rectangle" that surrounds the fields.
I actually wanted to *group* the fields, and hide that control only.
The end result being that everything would be hidden.

Any ideas, or do I have to pick thru each control?

Thanx again,
- Mike
I'm thinking this may be done using the OnCurrent event. Check the value of
LocalCurrency and if it equals "USD" then hide the other controls:
[quoted text clipped - 32 lines]
Regards,
- Mike
 
D

dymondjack

I could be wrong, but I don't think there's a way to do that in Access. In
VB.
Net and other apps I believe you can define something as a container, and
then set it's visible property, but I don't think Access has an equivalent
concept. I;m still using 2000, so maybe newer versions do?

I was just looking for my access reference book, because I'm pretty sure it
covers this, but apparently its at work and I'll have to try and look this up
if I get a few extra minutes tomorrow, but I'm pretty sure there's an example
in there to use a collection to loop through controls in the collection, in
which case it seems feasible that one could set the visibility of a group of
controls.

If I remember correctly, a collection is basically a group of any objects
that have something in common. I've never used them (this and arrays I think
may be pretty closely related, and both have been grey areas for me), but
this example I seem to remember seeing described how to do it.

I'm pretty sure that a2k has this. I've only used 2k2 and 2k3 but I know
the format is very similar for 2000.

Maybe someone who knows more about it could offer some advice, and I'll look
into it some more as I have time. This has been one of those things I've
been meaning to do for a long time but never got around to it (probably due
to my inexperience with arrays and collections).

If I happen to get this one nailed down I'll post back on it. This would be
nice...


--
Jack Leach
www.tristatemachine.com

- "Success is the ability to go from one failure to another with no loss of
enthusiasm." - Sir Winston Churchill
 
D

dymondjack

Got it!

Throw this in a command button click to toggle visibility for a group....



Dim col As New Collection
Dim ctl As Control

col.Add Me.ctlRequestID
col.Add Me.ctlTab
col.Add Me.ctltextbox

For Each ctl In col
ctl.Visible = Not ctl.Visible
Next ctl

Set ctl = Nothing
Set col = Nothing



Seems to work... (2k3)

--
Jack Leach
www.tristatemachine.com

- "Success is the ability to go from one failure to another with no loss of
enthusiasm." - Sir Winston Churchill
 
M

MikeF

Thanx Jack.

But ... where do I put the criteria?
[Might need a little elaborative assistance!!].

- Mike
 
D

dymondjack

Lets take it a step further and make the collection visible to the entire
form (defeats the purpose of a collection to add the items in the procedure
you want to edit the controls...)


In the form's module:

'-----
Option Compare Database
Option Explicit

Dim col As Collection
'-----



And in the form's Open event:

'-----
Private Sub Form_Open(Cancel As Integer)
col.Add Me.Control1
col.Add Me.Control2
...
End Sub
'-----



In the Form's Unload event:

Set col = Nothing


An (optional) private sub to loop the controls:

'-----
Private psShowCollection(Optional b As Boolean = True)
Dim ctl As Control
For Each ctl In col
ctl.Visible = b
Next ctl
Set ctl = Nothing
End Sub
'-----


And, from the current event, call the show controls:

'-----
Private Sub Form_Current
Call psShowCollection(Iif(Nz(Me.LocalCurrency, "") = "USD", False, True))
End Sub
'-----



look ok?

--
Jack Leach
www.tristatemachine.com

- "Success is the ability to go from one failure to another with no loss of
enthusiasm." - Sir Winston Churchill
 
J

Jack Leach

A few minor adjustments to my previous code after looking at it for a little
while.

Option Compare Database
Option Explicit

Dim col As Collection

This should be dimmed as Private:

Private col As Collection


An (optional) private sub to loop the controls:

I was thinking that by using a separate sub, you wouldn't need to dim the
ctl variable on each record change, but as it turns out the oncurrent event
calling the sub will run it every record change anyway, so we could get rid
of the sub and move the loop into the OnCurrent event to get rid of some
unnessesary code.


Neither one is major, but will make the code a bit cleaner


--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 

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