Hide/unhide image on forms

  • Thread starter Thread starter Harmannus
  • Start date Start date
H

Harmannus

Hallo,

On all my form i have a image "MyImage". Can i hide (not visible) or unhide
(visible) this image for "all" my forms at ones by changing 1 parameter
through code
in a module?

Thanx in advance for any replies.


Regards,

Harmannus
 
Harmannus said:
Hallo,

On all my form i have a image "MyImage". Can i hide (not visible) or
unhide (visible) this image for "all" my forms at ones by changing 1
parameter through code
in a module?

On all forms that are currently open, or on all forms in the database?
The control has the same name on alll the forms? I'm curious as to why
you would want to do this.
 
Hallo,

On all forms in the database & the control has the same name on all the
forms! Is a about this database image....

I have a hidden full access and limited access buttons on my switchboard
with
the below code in a module

I would like to add myimage.visible = true to the full access code and the
myimage.visible=false code to the limited access code.....

Sub SetFullStartupProperties()
ChangeProperty "StartupForm", dbText, "Switchboard" 'Warning! Change to
name of startupform
ChangeProperty "StartupShowDBWindow", dbBoolean, False
ChangeProperty "StartupShowStatusBar", dbBoolean, True
ChangeProperty "AllowBuiltinToolbars", dbBoolean, True
ChangeProperty "AllowToolbarChanges", dbBoolean, True
ChangeProperty "AllowFullMenus", dbBoolean, True
ChangeProperty "AllowShortcutMenus", dbBoolean, True
ChangeProperty "AllowBreakIntoCode", dbBoolean, True
ChangeProperty "AllowSpecialKeys", dbBoolean, True
ChangeProperty "AllowBypassKey", dbBoolean, True
End Sub

Sub SetLimitedStartupProperties()
ChangeProperty "StartupForm", dbText, "Switchboard" 'Warning! Change to
name of startupform
ChangeProperty "StartupShowDBWindow", dbBoolean, False
ChangeProperty "StartupShowStatusBar", dbBoolean, True
ChangeProperty "AllowBuiltinToolbars", dbBoolean, False
ChangeProperty "AllowToolbarChanges", dbBoolean, False
ChangeProperty "AllowFullMenus", dbBoolean, False
ChangeProperty "AllowShortcutMenus", dbBoolean, False
ChangeProperty "AllowBreakIntoCode", dbBoolean, True
ChangeProperty "AllowSpecialKeys", dbBoolean, False
ChangeProperty "AllowBypassKey", dbBoolean, False
End Sub

Can this be done?

Regards,

Harmannus
 
Harmannus said:
Hallo,

On all forms in the database & the control has the same name on all
the forms! Is a about this database image....

I have a hidden full access and limited access buttons on my
switchboard with
the below code in a module

I would like to add myimage.visible = true to the full access code
and the myimage.visible=false code to the limited access code.....

Sub SetFullStartupProperties()
ChangeProperty "StartupForm", dbText, "Switchboard" 'Warning! Change
to name of startupform
ChangeProperty "StartupShowDBWindow", dbBoolean, False
ChangeProperty "StartupShowStatusBar", dbBoolean, True
ChangeProperty "AllowBuiltinToolbars", dbBoolean, True
ChangeProperty "AllowToolbarChanges", dbBoolean, True
ChangeProperty "AllowFullMenus", dbBoolean, True
ChangeProperty "AllowShortcutMenus", dbBoolean, True
ChangeProperty "AllowBreakIntoCode", dbBoolean, True
ChangeProperty "AllowSpecialKeys", dbBoolean, True
ChangeProperty "AllowBypassKey", dbBoolean, True
End Sub

Sub SetLimitedStartupProperties()
ChangeProperty "StartupForm", dbText, "Switchboard" 'Warning!
Change to name of startupform
ChangeProperty "StartupShowDBWindow", dbBoolean, False
ChangeProperty "StartupShowStatusBar", dbBoolean, True
ChangeProperty "AllowBuiltinToolbars", dbBoolean, False
ChangeProperty "AllowToolbarChanges", dbBoolean, False
ChangeProperty "AllowFullMenus", dbBoolean, False
ChangeProperty "AllowShortcutMenus", dbBoolean, False
ChangeProperty "AllowBreakIntoCode", dbBoolean, True
ChangeProperty "AllowSpecialKeys", dbBoolean, False
ChangeProperty "AllowBypassKey", dbBoolean, False
End Sub

Can this be done?

Yes, certainly. I can think of two approaches -- the one you've
described, and a different one that I personally favor. As you asked,
it is possible to run a function to open every form in the database in
design view (but hidden), change the Visible property of this image
control, then save and close the form. The code (for A2K or later)
would look something like this:

'---- start of (untested) code ----
Sub SetControlVisibility( _
ControlName As String, _
VisibleOrNot As Boolean)

' Set the Visible property of the control named <ControlName>
' to <VisibleOrNot> on all forms in the database.

On Error GoTo Err_Handler

Dim ao As AccessObject

For Each ao In CurrentProject.AllForms

DoCmd.OpenForm ao.Name, acDesign, _
WindowMode:=acHidden

Forms(ao.Name).Controls(ControlName).Visible = VisibleOrNot

DoCmd.Close acForm, ao.Name, acSaveYes

Next ao

Exit_Point:
If Not ao Is Nothing Then
DoCmd.Close acForm, ao.Name, acSaveNo
End If
Exit Sub

Err_Handler:
If Err.Number = 2465 Then
' Couldn't find control.
Resume Next
Else
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point
End If

End Sub
'---- end of code ----

You would call it like this:

SetControlVisibility("MyImage", False) ' hide image
SetControlVisibility("MyImage", True) ' show image

Something along those lines should work. If the code is being run
behind a form, you'll want to add special handling for that form.

However, I don't like the idea of making a lot of (saved) design changes
at run time. Among other things, I think it's going to lead to
consistent database bloat, plus it's going to take a certain amount of
time whenever the database is opened -- unless you only run this code
the first time a copy of the front-end is opened. Instead, how about
calling a function from each form's Open event that determines whether
the control should be visible or not, and shows or hides it accordingly?
Such a function might look like this (though I don't know how you
determine whether the control should be shown or hidden):

---- start of (untested) alternative code ----
Function SetControlVisibility(ctl As Control)

If <... control should be visible ...> Then
ctl.Visible = True
Else
ctl.Visible = False
End If

End Function
---- end of alternative code ----

Then you can put a function-call expression directly into each form's
OnOpen property:

=SetControlVisibility([MyImage])

Yes, it's more trouble to change all the existing forms, but it's only a
simple change you make once. If there are a lot of forms you can even
write a quickie program to set that property in all of them.

Now, if determining whether to show or hide the form is a time-consuming
process that you don't want to do each time the form is opened, you
could get around that by figuring it out only once, on startup, and
saving the information in a table or a global variable or property, so
that the function only needs to check that location. In fact, you could
just get the value of one of the options you've set in your
Set...StartupProperties routines.
 
One more suggestion to add to Dirk's. If you have the image on a subform,
and then add the subform to each of the forms rather than the image, then
you've only got to change one form to affect the whole database.
 
Hallo,

Thanx for the assistance and code tips!

Still a bit confused though...

I would like to use =SetControlVisibility([MyImage]) in the OnOpen Event of
each form...

What code can i set in the FullAccess or LimitedAccess (as shown below) to
triger the set controlVisibility?

Thanx in advance for a reply.


Regards,

Harmannus



Dirk Goldgar said:
Harmannus said:
Hallo,

On all forms in the database & the control has the same name on all
the forms! Is a about this database image....

I have a hidden full access and limited access buttons on my
switchboard with
the below code in a module

I would like to add myimage.visible = true to the full access code
and the myimage.visible=false code to the limited access code.....

Sub SetFullStartupProperties()
ChangeProperty "StartupForm", dbText, "Switchboard" 'Warning! Change
to name of startupform
ChangeProperty "StartupShowDBWindow", dbBoolean, False
ChangeProperty "StartupShowStatusBar", dbBoolean, True
ChangeProperty "AllowBuiltinToolbars", dbBoolean, True
ChangeProperty "AllowToolbarChanges", dbBoolean, True
ChangeProperty "AllowFullMenus", dbBoolean, True
ChangeProperty "AllowShortcutMenus", dbBoolean, True
ChangeProperty "AllowBreakIntoCode", dbBoolean, True
ChangeProperty "AllowSpecialKeys", dbBoolean, True
ChangeProperty "AllowBypassKey", dbBoolean, True
End Sub

Sub SetLimitedStartupProperties()
ChangeProperty "StartupForm", dbText, "Switchboard" 'Warning!
Change to name of startupform
ChangeProperty "StartupShowDBWindow", dbBoolean, False
ChangeProperty "StartupShowStatusBar", dbBoolean, True
ChangeProperty "AllowBuiltinToolbars", dbBoolean, False
ChangeProperty "AllowToolbarChanges", dbBoolean, False
ChangeProperty "AllowFullMenus", dbBoolean, False
ChangeProperty "AllowShortcutMenus", dbBoolean, False
ChangeProperty "AllowBreakIntoCode", dbBoolean, True
ChangeProperty "AllowSpecialKeys", dbBoolean, False
ChangeProperty "AllowBypassKey", dbBoolean, False
End Sub

Can this be done?

Yes, certainly. I can think of two approaches -- the one you've
described, and a different one that I personally favor. As you asked,
it is possible to run a function to open every form in the database in
design view (but hidden), change the Visible property of this image
control, then save and close the form. The code (for A2K or later)
would look something like this:

'---- start of (untested) code ----
Sub SetControlVisibility( _
ControlName As String, _
VisibleOrNot As Boolean)

' Set the Visible property of the control named <ControlName>
' to <VisibleOrNot> on all forms in the database.

On Error GoTo Err_Handler

Dim ao As AccessObject

For Each ao In CurrentProject.AllForms

DoCmd.OpenForm ao.Name, acDesign, _
WindowMode:=acHidden

Forms(ao.Name).Controls(ControlName).Visible = VisibleOrNot

DoCmd.Close acForm, ao.Name, acSaveYes

Next ao

Exit_Point:
If Not ao Is Nothing Then
DoCmd.Close acForm, ao.Name, acSaveNo
End If
Exit Sub

Err_Handler:
If Err.Number = 2465 Then
' Couldn't find control.
Resume Next
Else
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point
End If

End Sub
'---- end of code ----

You would call it like this:

SetControlVisibility("MyImage", False) ' hide image
SetControlVisibility("MyImage", True) ' show image

Something along those lines should work. If the code is being run
behind a form, you'll want to add special handling for that form.

However, I don't like the idea of making a lot of (saved) design changes
at run time. Among other things, I think it's going to lead to
consistent database bloat, plus it's going to take a certain amount of
time whenever the database is opened -- unless you only run this code
the first time a copy of the front-end is opened. Instead, how about
calling a function from each form's Open event that determines whether
the control should be visible or not, and shows or hides it accordingly?
Such a function might look like this (though I don't know how you
determine whether the control should be shown or hidden):

---- start of (untested) alternative code ----
Function SetControlVisibility(ctl As Control)

If <... control should be visible ...> Then
ctl.Visible = True
Else
ctl.Visible = False
End If

End Function
---- end of alternative code ----

Then you can put a function-call expression directly into each form's
OnOpen property:

=SetControlVisibility([MyImage])

Yes, it's more trouble to change all the existing forms, but it's only a
simple change you make once. If there are a lot of forms you can even
write a quickie program to set that property in all of them.

Now, if determining whether to show or hide the form is a time-consuming
process that you don't want to do each time the form is opened, you
could get around that by figuring it out only once, on startup, and
saving the information in a table or a global variable or property, so
that the function only needs to check that location. In fact, you could
just get the value of one of the options you've set in your
Set...StartupProperties routines.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Harmannus said:
Hallo,

Thanx for the assistance and code tips!

Still a bit confused though...

I would like to use =SetControlVisibility([MyImage]) in the OnOpen
Event of each form...

What code can i set in the FullAccess or LimitedAccess (as shown
below) to triger the set controlVisibility?

Thanx in advance for a reply.


Regards,

Harmannus



Dirk Goldgar said:
Harmannus said:
Hallo,

On all forms in the database & the control has the same name on all
the forms! Is a about this database image....

I have a hidden full access and limited access buttons on my
switchboard with
the below code in a module

I would like to add myimage.visible = true to the full access code
and the myimage.visible=false code to the limited access code.....

Sub SetFullStartupProperties()
ChangeProperty "StartupForm", dbText, "Switchboard" 'Warning!
Change to name of startupform
ChangeProperty "StartupShowDBWindow", dbBoolean, False
ChangeProperty "StartupShowStatusBar", dbBoolean, True
ChangeProperty "AllowBuiltinToolbars", dbBoolean, True
ChangeProperty "AllowToolbarChanges", dbBoolean, True
ChangeProperty "AllowFullMenus", dbBoolean, True
ChangeProperty "AllowShortcutMenus", dbBoolean, True
ChangeProperty "AllowBreakIntoCode", dbBoolean, True
ChangeProperty "AllowSpecialKeys", dbBoolean, True
ChangeProperty "AllowBypassKey", dbBoolean, True
End Sub

Sub SetLimitedStartupProperties()
ChangeProperty "StartupForm", dbText, "Switchboard" 'Warning!
Change to name of startupform
ChangeProperty "StartupShowDBWindow", dbBoolean, False
ChangeProperty "StartupShowStatusBar", dbBoolean, True
ChangeProperty "AllowBuiltinToolbars", dbBoolean, False
ChangeProperty "AllowToolbarChanges", dbBoolean, False
ChangeProperty "AllowFullMenus", dbBoolean, False
ChangeProperty "AllowShortcutMenus", dbBoolean, False
ChangeProperty "AllowBreakIntoCode", dbBoolean, True
ChangeProperty "AllowSpecialKeys", dbBoolean, False
ChangeProperty "AllowBypassKey", dbBoolean, False
End Sub

Can this be done?

Yes, certainly. I can think of two approaches -- the one you've
described, and a different one that I personally favor. As you
asked, it is possible to run a function to open every form in the
database in design view (but hidden), change the Visible property of
this image control, then save and close the form. The code (for A2K
or later) would look something like this:

'---- start of (untested) code ----
Sub SetControlVisibility( _
ControlName As String, _
VisibleOrNot As Boolean)

' Set the Visible property of the control named <ControlName>
' to <VisibleOrNot> on all forms in the database.

On Error GoTo Err_Handler

Dim ao As AccessObject

For Each ao In CurrentProject.AllForms

DoCmd.OpenForm ao.Name, acDesign, _
WindowMode:=acHidden

Forms(ao.Name).Controls(ControlName).Visible = VisibleOrNot

DoCmd.Close acForm, ao.Name, acSaveYes

Next ao

Exit_Point:
If Not ao Is Nothing Then
DoCmd.Close acForm, ao.Name, acSaveNo
End If
Exit Sub

Err_Handler:
If Err.Number = 2465 Then
' Couldn't find control.
Resume Next
Else
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point
End If

End Sub
'---- end of code ----

You would call it like this:

SetControlVisibility("MyImage", False) ' hide image
SetControlVisibility("MyImage", True) ' show image

Something along those lines should work. If the code is being run
behind a form, you'll want to add special handling for that form.

However, I don't like the idea of making a lot of (saved) design
changes at run time. Among other things, I think it's going to lead
to consistent database bloat, plus it's going to take a certain
amount of time whenever the database is opened -- unless you only
run this code the first time a copy of the front-end is opened.
Instead, how about calling a function from each form's Open event
that determines whether the control should be visible or not, and
shows or hides it accordingly? Such a function might look like this
(though I don't know how you determine whether the control should be
shown or hidden):

---- start of (untested) alternative code ----
Function SetControlVisibility(ctl As Control)

If <... control should be visible ...> Then
ctl.Visible = True
Else
ctl.Visible = False
End If

End Function
---- end of alternative code ----

Then you can put a function-call expression directly into each form's
OnOpen property:

=SetControlVisibility([MyImage])

Yes, it's more trouble to change all the existing forms, but it's
only a simple change you make once. If there are a lot of forms you
can even write a quickie program to set that property in all of them.

Now, if determining whether to show or hide the form is a
time-consuming process that you don't want to do each time the form
is opened, you could get around that by figuring it out only once,
on startup, and saving the information in a table or a global
variable or property, so that the function only needs to check that
location. In fact, you could just get the value of one of the
options you've set in your Set...StartupProperties routines.

Why not set up the SetControlVisibility() function to test one of the
properties that you are setting in that function? Maybe something like
this:

---- start of code ----
Function SetControlVisibility(ctl As Control)

On Error Resume Next

ctl.Visible = DBEngine(0)(0).Properties("AllowFullMenus")

End Function
---- end of code ----

Then you wouldn't have to put any extra code in your
Set...StartupProperties routines at all.
 
Hallo,

Works great ;-)

Thanx for the assistance!


Regards,

Harmannus

Dirk Goldgar said:
Harmannus said:
Hallo,

Thanx for the assistance and code tips!

Still a bit confused though...

I would like to use =SetControlVisibility([MyImage]) in the OnOpen
Event of each form...

What code can i set in the FullAccess or LimitedAccess (as shown
below) to triger the set controlVisibility?

Thanx in advance for a reply.


Regards,

Harmannus



Dirk Goldgar said:
Hallo,

On all forms in the database & the control has the same name on all
the forms! Is a about this database image....

I have a hidden full access and limited access buttons on my
switchboard with
the below code in a module

I would like to add myimage.visible = true to the full access code
and the myimage.visible=false code to the limited access code.....

Sub SetFullStartupProperties()
ChangeProperty "StartupForm", dbText, "Switchboard" 'Warning!
Change to name of startupform
ChangeProperty "StartupShowDBWindow", dbBoolean, False
ChangeProperty "StartupShowStatusBar", dbBoolean, True
ChangeProperty "AllowBuiltinToolbars", dbBoolean, True
ChangeProperty "AllowToolbarChanges", dbBoolean, True
ChangeProperty "AllowFullMenus", dbBoolean, True
ChangeProperty "AllowShortcutMenus", dbBoolean, True
ChangeProperty "AllowBreakIntoCode", dbBoolean, True
ChangeProperty "AllowSpecialKeys", dbBoolean, True
ChangeProperty "AllowBypassKey", dbBoolean, True
End Sub

Sub SetLimitedStartupProperties()
ChangeProperty "StartupForm", dbText, "Switchboard" 'Warning!
Change to name of startupform
ChangeProperty "StartupShowDBWindow", dbBoolean, False
ChangeProperty "StartupShowStatusBar", dbBoolean, True
ChangeProperty "AllowBuiltinToolbars", dbBoolean, False
ChangeProperty "AllowToolbarChanges", dbBoolean, False
ChangeProperty "AllowFullMenus", dbBoolean, False
ChangeProperty "AllowShortcutMenus", dbBoolean, False
ChangeProperty "AllowBreakIntoCode", dbBoolean, True
ChangeProperty "AllowSpecialKeys", dbBoolean, False
ChangeProperty "AllowBypassKey", dbBoolean, False
End Sub

Can this be done?

Yes, certainly. I can think of two approaches -- the one you've
described, and a different one that I personally favor. As you
asked, it is possible to run a function to open every form in the
database in design view (but hidden), change the Visible property of
this image control, then save and close the form. The code (for A2K
or later) would look something like this:

'---- start of (untested) code ----
Sub SetControlVisibility( _
ControlName As String, _
VisibleOrNot As Boolean)

' Set the Visible property of the control named <ControlName>
' to <VisibleOrNot> on all forms in the database.

On Error GoTo Err_Handler

Dim ao As AccessObject

For Each ao In CurrentProject.AllForms

DoCmd.OpenForm ao.Name, acDesign, _
WindowMode:=acHidden

Forms(ao.Name).Controls(ControlName).Visible = VisibleOrNot

DoCmd.Close acForm, ao.Name, acSaveYes

Next ao

Exit_Point:
If Not ao Is Nothing Then
DoCmd.Close acForm, ao.Name, acSaveNo
End If
Exit Sub

Err_Handler:
If Err.Number = 2465 Then
' Couldn't find control.
Resume Next
Else
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point
End If

End Sub
'---- end of code ----

You would call it like this:

SetControlVisibility("MyImage", False) ' hide image
SetControlVisibility("MyImage", True) ' show image

Something along those lines should work. If the code is being run
behind a form, you'll want to add special handling for that form.

However, I don't like the idea of making a lot of (saved) design
changes at run time. Among other things, I think it's going to lead
to consistent database bloat, plus it's going to take a certain
amount of time whenever the database is opened -- unless you only
run this code the first time a copy of the front-end is opened.
Instead, how about calling a function from each form's Open event
that determines whether the control should be visible or not, and
shows or hides it accordingly? Such a function might look like this
(though I don't know how you determine whether the control should be
shown or hidden):

---- start of (untested) alternative code ----
Function SetControlVisibility(ctl As Control)

If <... control should be visible ...> Then
ctl.Visible = True
Else
ctl.Visible = False
End If

End Function
---- end of alternative code ----

Then you can put a function-call expression directly into each form's
OnOpen property:

=SetControlVisibility([MyImage])

Yes, it's more trouble to change all the existing forms, but it's
only a simple change you make once. If there are a lot of forms you
can even write a quickie program to set that property in all of them.

Now, if determining whether to show or hide the form is a
time-consuming process that you don't want to do each time the form
is opened, you could get around that by figuring it out only once,
on startup, and saving the information in a table or a global
variable or property, so that the function only needs to check that
location. In fact, you could just get the value of one of the
options you've set in your Set...StartupProperties routines.

Why not set up the SetControlVisibility() function to test one of the
properties that you are setting in that function? Maybe something like
this:

---- start of code ----
Function SetControlVisibility(ctl As Control)

On Error Resume Next

ctl.Visible = DBEngine(0)(0).Properties("AllowFullMenus")

End Function
---- end of code ----

Then you wouldn't have to put any extra code in your
Set...StartupProperties routines at all.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top