PDA

Vollständige Version anzeigen : Objekte Ausblenden


TommyK
06.03.2006, 05:29
Hallo,

heute ein Bsp-Code zum Ausblenden von Objekten im Datenbankfenster (ab A00).
Folgenden Code in ein neues Modul kopieren:
<div><link href="http://www.ms-office-forum.net/forum/externals/codeconv.css" rel="stylesheet"><pre><span class="TOKEN">Public</span> <span class="TOKEN">Enum</span> ObjectType
Tables = 0
Querys = 1
Forms = 2
Reports = 3
Modules = 5
Scripts = 4
<span class="TOKEN">End</span> <span class="TOKEN">Enum</span>
&nbsp;
<span class="TOKEN">Public</span> <span class="TOKEN">Enum</span> HiddenType
Sichtbar = 0
Unsichtbar = -1
<span class="TOKEN">End</span> <span class="TOKEN">Enum</span>
&nbsp;
<span class="TOKEN">Public Sub</span> HiddenObject(iTyp <span class="TOKEN">As</span> ObjectType, iChange <span class="TOKEN">As</span> HiddenType)
<span class="TOKEN">On</span> <span class="TOKEN">Error</span> <span class="TOKEN">Resume</span> <span class="TOKEN">Next</span>
<span class="TOKEN">Dim</span> rst <span class="TOKEN">As</span> DAO.Recordset
<span class="TOKEN">Dim</span> sSQL <span class="TOKEN">As</span> <span class="TOKEN">String</span>
&nbsp;
sSQL = &quot;SELECT MSysObjects.Name, MSysObjects.Type FROM MSysObjects WHERE &quot;
<span class="TOKEN">If</span> iTyp = Tables <span class="TOKEN">Then</span>
sSQL = sSQL &amp; &quot;(((MSysObjects.Name) <span class="TOKEN">Not</span> Like 'MSys*') AND ((MSysObjects.Type)=1 <span class="TOKEN">Or</span> (MSysObjects.Type)=6))&quot;
<span class="TOKEN">ElseIf</span> iTyp = Querys <span class="TOKEN">Then</span>
sSQL = sSQL &amp; &quot;(((MSysObjects.Name) <span class="TOKEN">Not</span> Like '~*') AND ((MSysObjects.Type)=5));&quot;
<span class="TOKEN">ElseIf</span> iTyp = Forms <span class="TOKEN">Then</span>
sSQL = sSQL &amp; &quot;(((MSysObjects.Type)=-32768));&quot;
<span class="TOKEN">ElseIf</span> iTyp = Reports <span class="TOKEN">Then</span>
sSQL = sSQL &amp; &quot;(((MSysObjects.Type)=-32764));&quot;
<span class="TOKEN">ElseIf</span> iTyp = Modules <span class="TOKEN">Then</span>
sSQL = sSQL &amp; &quot;(((MSysObjects.Type)=-32761));&quot;
<span class="TOKEN">ElseIf</span> iTyp = Scripts <span class="TOKEN">Then</span>
sSQL = sSQL &amp; &quot;(((MSysObjects.Type)=-32766));&quot;
<span class="TOKEN">End</span> <span class="TOKEN">If</span>
<span class="TOKEN">Set</span> rst = CurrentDb.OpenRecordset(sSQL)
<span class="TOKEN">Do</span> <span class="TOKEN">While</span> <span class="TOKEN">Not</span> rst.EOF
Application.SetHiddenAttribute iTyp, rst!Name, iChange
rst.MoveNext
<span class="TOKEN">Loop</span>
rst.Close: <span class="TOKEN">Set</span> rst = <span class="TOKEN">Nothing</span>
<span class="TOKEN">End</span> <span class="TOKEN">Sub</span></pre></div>
Code eingefügt mit dem MOF Code Converter (http://www.ms-office-forum.net/forum/codeconverter.php)

Der Aufruf könnte dann so aussehen:
z.B. alle Tabellen ausblenden:
HiddenObject Tables, Unsichtbar
Alle Tabellen einblenden:
HiddenObject Tables, Sichtbar
Hinweis: Das Formular aus dem der Code aufgerufen wird, kann nicht ausgeblendet werden.