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)