PDA

Vollständige Version anzeigen : Dateidialog (Öffnen & Speichern) Für Access 97/2000/XP


Günther Kramer
28.12.2002, 10:40
<img src="images/codearchiv/dateidialog.gif" border=0><br><br>Fügen Sie den folgenden Code in ein Modul (neu oder vorhanden) ein.

<div><link href="http://www.ms-office-forum.net/forum/externals/codeconv.css" rel="stylesheet"><pre><span class="TOKEN">Option</span> <span class="TOKEN">Compare</span> <span class="TOKEN">Database</span>
<span class="TOKEN">Option</span> <span class="TOKEN">Explicit</span>
&nbsp;
<span class="TOKEN">Type</span> DateiDialogStruktur
lStructSize <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
hwndOwner <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
hInstance <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
lpstrFilter <span class="TOKEN">As</span> <span class="TOKEN">String</span>
lpstrCustomFilter <span class="TOKEN">As</span> <span class="TOKEN">String</span>
nMaxCustFilter <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
nFilterIndex <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
lpstrFile <span class="TOKEN">As</span> <span class="TOKEN">String</span>
nMaxFile <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
lpstrFileTitle <span class="TOKEN">As</span> <span class="TOKEN">String</span>
nMaxFileTitle <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
lpstrInitialDir <span class="TOKEN">As</span> <span class="TOKEN">String</span>
lpstrTitle <span class="TOKEN">As</span> <span class="TOKEN">String</span>
flags <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
nFileOffset <span class="TOKEN">As</span> <span class="TOKEN">Integer</span>
nFileExtension <span class="TOKEN">As</span> <span class="TOKEN">Integer</span>
lpstrDefExt <span class="TOKEN">As</span> <span class="TOKEN">String</span>
lCustData <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
lpfnHook <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
lpTemplateName <span class="TOKEN">As</span> <span class="TOKEN">String</span>
<span class="TOKEN">End</span> <span class="TOKEN">Type</span>
&nbsp;
<span class="TOKEN">Declare</span> <span class="TOKEN">Function</span> GetOpenFileName <span class="TOKEN">Lib</span> &quot;comdlg32.dll&quot; <span class="TOKEN">Alias</span> &quot;GetOpenFileNameA&quot; _
(DateiDialogStruktur <span class="TOKEN">As</span> DateiDialogStruktur) <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
<span class="TOKEN">Declare</span> <span class="TOKEN">Function</span> GetSaveFileName <span class="TOKEN">Lib</span> &quot;comdlg32.dll&quot; <span class="TOKEN">Alias</span> &quot;GetSaveFileNameA&quot; _
(DateiDialogStruktur <span class="TOKEN">As</span> DateiDialogStruktur) <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
&nbsp;
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_ALLOWMULTISELECT = &amp;H200
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_CREATEPROMPT = &amp;H2000
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_ENABLEHOOK = &amp;H20
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_ENABLETEMPLATE = &amp;H40
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_ENABLETEMPLATEHANDLE = &amp;H80
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_EXPLORER = &amp;H80000
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_EXTENSIONDIFFERENT = &amp;H400
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_FILEMUSTEXIST = &amp;H1000
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_HIDEREADONLY = &amp;H4
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_LONGNAMES = &amp;H200000
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_NOCHANGEDIR = &amp;H8
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_NODEREFERENCELINKS = &amp;H100000
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_NOLONGNAMES = &amp;H40000
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_NONETWORKBUTTON = &amp;H20000
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_NOREADONLYRETURN = &amp;H8000
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_NOTESTFILECREATE = &amp;H10000
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_NOVALIDATE = &amp;H100
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_OVERWRITEPROMPT = &amp;H2
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_PATHMUSTEXIST = &amp;H800
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_READONLY = &amp;H1
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_SHAREAWARE = &amp;H4000
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_SHAREFALLTHROUGH = 2
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_SHARENOWARN = 1
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_SHAREWARN = 0
<span class="TOKEN">Public</span> <span class="TOKEN">Const</span> OFN_SHOWHELP = &amp;H10
&nbsp;
<span class="TOKEN">Dim</span> DateiDialogStruktur <span class="TOKEN">As</span> DateiDialogStruktur
&nbsp;
<span class="TOKEN">Function</span> DateiOeffnen(Verzeichnis <span class="TOKEN">As</span> String, Fenstertitel <span class="TOKEN">As</span> <span class="TOKEN">String</span>) <span class="TOKEN">As</span> <span class="TOKEN">String</span>
<span class="TOKEN">On Error GoTo</span> Err_DateiOeffnen
&nbsp;
<span class="TOKEN">Dim</span> Dateityp <span class="TOKEN">As</span> <span class="TOKEN">String</span>
<span class="TOKEN">Dim</span> Dateiname_mit_Pfad <span class="TOKEN">As</span> <span class="TOKEN">String</span>
<span class="TOKEN">Dim</span> Dateiname <span class="TOKEN">As</span> <span class="TOKEN">String</span>
<span class="TOKEN">Dim</span> Rueckwerte <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
&nbsp;
Dateityp = &quot;&quot;
&nbsp;
<span class="REM">' Dateitypen in der Auswahlliste des Dateityp's</span>
<span class="REM">' Alle Dateien</span>
Dateityp = Dateityp &amp; &quot;Alle Dateien (*.*)&quot; &amp; Chr$(0) &amp; &quot;*.*&quot; &amp; Chr$(0)
&nbsp;
<span class="REM">' Access-Dateitypen</span>
Dateityp = Dateityp &amp; _
&quot;Microsoft Access-Datenbanken (*.mdb)&quot; &amp; Chr$(0) &amp; &quot;*.mdb&quot; &amp; Chr$(0)
&nbsp;
Dateityp = Dateityp &amp; _
&quot;Add-Ins (*.mda)&quot; &amp; Chr$(0) &amp; &quot;*.mda&quot; &amp; Chr$(0)
&nbsp;
Dateityp = Dateityp &amp; _
&quot;Arbeitsgruppen-Dateien (*.mdw)&quot; &amp; Chr$(0) &amp; &quot;*.mdw&quot; &amp; Chr$(0)
&nbsp;
Dateityp = Dateityp &amp; _
&quot;MDE-Dateien (*.mde)&quot; &amp; Chr$(0) &amp; &quot;*.mde&quot; &amp; Chr$(0)
&nbsp;
<span class="REM">' Word-Dateitypen</span>
<span class="REM">' Word-Dokumente (*.doc)</span>
<span class="REM">' Dokumentenvorlagen (*.dot)</span>
<span class="REM">' Rich Text Format (*.rtf)</span>
<span class="REM">' Textdateien (*.txt)</span>
<span class="REM">' Schedule+-Kontakte (*.scd)</span>
<span class="REM">' Persönliches Adreßbuch (*.pab)</span>
<span class="REM">' Outlook-Adreßbuch (*.olk)</span>
<span class="REM">' MS-DOS Text mit Layout (*.asc)</span>
<span class="REM">' Text mit Layout (*.ans)</span>
<span class="REM">' HTML Document (*.htm;*.html;*.htx)</span>
<span class="REM">' Windows Write (*.wri)</span>
<span class="REM">' Lotus 1-2-3 (*.wk1;*.wk3;*.wk4)</span>
<span class="REM">' WordPerfect 6.x (*.wpd;*.doc)</span>
<span class="REM">' Microsoft Excel-Arbeitsmappen (*.xls)</span>
<span class="REM">' Works 3.0 für Windows (*.wps)</span>
<span class="REM">' Works 4.0 für Windows (*.wps)</span>
&nbsp;
<span class="REM">' Excel-Dateitypen</span>
<span class="REM">' Textdateien (*.prn;*.txt;*.csv)</span>
<span class="REM">' QuattroPro/DOS-Dateien (*.wq1)</span>
<span class="REM">' Microsoft Works 2.0-Dateien (*.wks)</span>
<span class="REM">' dBASE-Dateien (*.dbf)</span>
<span class="REM">' Add-Ins (*.xla;*.xll)</span>
<span class="REM">' Mustervorlagen (*.xlt)</span>
<span class="REM">' Arbeitsbereiche (*.xlw)</span>
<span class="REM">' Tabellen (*.xls)</span>
&nbsp;
<span class="REM">' Sicherungsdateien (*.xlk;*.bak)</span>
<span class="REM">' HTML-Dateien (*.html;*.htm)</span>
&nbsp;
&nbsp;
<span class="REM">' Vorgegebenes Verzeichnis</span>
<span class="TOKEN">If</span> Verzeichnis = &quot;&quot; <span class="TOKEN">Then</span>
<span class="REM"> ' Wenn leer, dann soll das aktuelle Verzeichnis verwendet werden</span>
Verzeichnis = CurDir$ &amp; Chr$(0)
<span class="TOKEN">Else</span>
<span class="REM"> ' ANSI &quot;0&quot; an das übergebene Verzeichnis anhängen</span>
Verzeichnis = Verzeichnis &amp; Chr$(0)
<span class="TOKEN">End</span> <span class="TOKEN">If</span>
&nbsp;
<span class="TOKEN">If</span> Fenstertitel = &quot;&quot; <span class="TOKEN">Then</span>
<span class="REM"> ' Wenn kein Titel übergeben worden ist</span>
Fenstertitel = &quot;Datei &ouml;ffnen&quot;
<span class="TOKEN">Else</span>
<span class="REM"> ' ANSI &quot;0&quot; an übergebenen Fenstertitel anhängen</span>
Fenstertitel = Fenstertitel &amp; Chr$(0)
<span class="TOKEN">End</span> <span class="TOKEN">If</span>
&nbsp;
<span class="REM">' Speicherplatz für Dateieintrag (mit Pfadangabe) reservieren</span>
Dateiname_mit_Pfad = Space$(255) &amp; Chr$(0)
&nbsp;
<span class="REM">' Speicherplatz für Dateieintrag (ohne Pfadangabe) reservieren</span>
Dateiname = Space$(255) &amp; Chr$(0)
&nbsp;
<span class="REM">'Datenstruktur von DateiDialogStruktur festlegen</span>
DateiDialogStruktur.lStructSize = Len(DateiDialogStruktur)
DateiDialogStruktur.hwndOwner = 0&amp;
<span class="REM"> 'DateiDialogStruktur.hwndOwner = Application.hWndAccessApp</span>
DateiDialogStruktur.lpstrFilter = Dateityp
DateiDialogStruktur.nFilterIndex = 1
DateiDialogStruktur.lpstrFile = Dateiname_mit_Pfad
DateiDialogStruktur.nMaxFile = Len(Dateiname_mit_Pfad)
DateiDialogStruktur.lpstrFileTitle = Dateiname
DateiDialogStruktur.nMaxFileTitle = Len(Dateiname)
DateiDialogStruktur.lpstrInitialDir = Verzeichnis
DateiDialogStruktur.lpstrTitle = Fenstertitel
DateiDialogStruktur.flags = OFN_FILEMUSTEXIST <span class="TOKEN">Or</span> OFN_PATHMUSTEXIST _
<span class="TOKEN">Or</span> OFN_HIDEREADONLY <span class="TOKEN">Or</span> OFN_LONGNAMES
DateiDialogStruktur.nFileOffset = 0
DateiDialogStruktur.nFileExtension = 0
DateiDialogStruktur.lCustData = 0
DateiDialogStruktur.lpfnHook = 0
DateiDialogStruktur.lpTemplateName = &quot;&quot;
&nbsp;
Rueckwerte = GetOpenFileName(DateiDialogStruktur)
&nbsp;
<span class="TOKEN">If</span> Rueckwerte &lt;&gt; 0 <span class="TOKEN">Then</span>
DateiOeffnen = Left(DateiDialogStruktur.lpstrFile, _
InStr(DateiDialogStruktur.lpstrFile, Chr$(0)) - 1)
<span class="TOKEN">End</span> <span class="TOKEN">If</span>
&nbsp;
Exit_DateiOeffnen:
<span class="TOKEN">Exit Function</span>
&nbsp;
Err_DateiOeffnen:
MsgBox Err.Description
<span class="TOKEN">Resume</span> Exit_DateiOeffnen
&nbsp;
<span class="TOKEN">End</span> <span class="TOKEN">Function</span>
<span class="TOKEN">Function</span> DateiSpeichern(Verzeichnis <span class="TOKEN">As</span> String, Fenstertitel <span class="TOKEN">As</span> <span class="TOKEN">String</span>) <span class="TOKEN">As</span> <span class="TOKEN">String</span>
<span class="TOKEN">On Error GoTo</span> Err_DateiSpeichern
&nbsp;
<span class="TOKEN">Dim</span> Dateityp <span class="TOKEN">As</span> <span class="TOKEN">String</span>
<span class="TOKEN">Dim</span> Dateiname_mit_Pfad <span class="TOKEN">As</span> <span class="TOKEN">String</span>
<span class="TOKEN">Dim</span> Dateiname <span class="TOKEN">As</span> <span class="TOKEN">String</span>
<span class="TOKEN">Dim</span> Rueckwerte <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
&nbsp;
<span class="REM">' Dateitypen in der Auswahlliste des Dateityp's</span>
<span class="REM">' Alle Dateien</span>
Dateityp = Dateityp &amp; &quot;Alle Dateien (*.*)&quot; &amp; Chr$(0) &amp; &quot;*.*&quot; &amp; Chr$(0)
&nbsp;
<span class="REM">' Access-Dateitypen</span>
Dateityp = Dateityp &amp; _
&quot;Microsoft Access-Datenbanken (*.mdb)&quot; &amp; Chr$(0) &amp; &quot;*.mdb&quot; &amp; Chr$(0)
&nbsp;
Dateityp = Dateityp &amp; _
&quot;Add-Ins (*.mda)&quot; &amp; Chr$(0) &amp; &quot;*.mda&quot; &amp; Chr$(0)
&nbsp;
Dateityp = Dateityp &amp; _
&quot;Arbeitsgruppen-Dateien (*.mdw)&quot; &amp; Chr$(0) &amp; &quot;*.mdw&quot; &amp; Chr$(0)
&nbsp;
Dateityp = Dateityp &amp; _
&quot;MDE-Dateien (*.mde)&quot; &amp; Chr$(0) &amp; &quot;*.mde&quot; &amp; Chr$(0)
&nbsp;
<span class="REM">' Vorgegebenes Verzeichnis</span>
<span class="TOKEN">If</span> Verzeichnis = &quot;&quot; <span class="TOKEN">Then</span>
<span class="REM"> ' Wenn leer, dann soll das aktuelle Verzeichnis verwendet werden</span>
Verzeichnis = CurDir$ &amp; Chr$(0)
<span class="TOKEN">Else</span>
<span class="REM"> ' ANSI &quot;0&quot; an das übergebene Verzeichnis anhängen</span>
Verzeichnis = Verzeichnis &amp; Chr$(0)
<span class="TOKEN">End</span> <span class="TOKEN">If</span>
&nbsp;
<span class="TOKEN">If</span> Fenstertitel = &quot;&quot; <span class="TOKEN">Then</span>
<span class="REM"> ' Wenn kein Titel übergeben worden ist</span>
Fenstertitel = &quot;Datei speichern&quot;
<span class="TOKEN">Else</span>
<span class="REM"> ' ANSI &quot;0&quot; an übergebenen Fenstertitel anhängen</span>
Fenstertitel = Fenstertitel &amp; Chr$(0)
<span class="TOKEN">End</span> <span class="TOKEN">If</span>
&nbsp;
<span class="REM">' Speicherplatz für Dateieintrag (mit Pfadangabe) reservieren</span>
Dateiname_mit_Pfad = Space$(255) &amp; Chr$(0)
&nbsp;
<span class="REM">' Speicherplatz für Dateieintrag (ohne Pfadangabe) reservieren</span>
Dateiname = Space$(255) &amp; Chr$(0)
&nbsp;
<span class="REM">'Datenstruktur von DateiDialogStruktur festlegen</span>
DateiDialogStruktur.lStructSize = Len(DateiDialogStruktur)
DateiDialogStruktur.hwndOwner = 0&amp;
<span class="REM"> 'DateiDialogStruktur.hwndOwner = Application.hWndAccessApp</span>
DateiDialogStruktur.lpstrFilter = Dateityp
DateiDialogStruktur.nFilterIndex = 1
DateiDialogStruktur.lpstrFile = Dateiname_mit_Pfad
DateiDialogStruktur.nMaxFile = Len(Dateiname_mit_Pfad)
DateiDialogStruktur.lpstrFileTitle = Dateiname
DateiDialogStruktur.nMaxFileTitle = Len(Dateiname)
DateiDialogStruktur.lpstrInitialDir = Verzeichnis
DateiDialogStruktur.lpstrTitle = Fenstertitel
DateiDialogStruktur.flags = OFN_HIDEREADONLY <span class="TOKEN">Or</span> OFN_OVERWRITEPROMPT
DateiDialogStruktur.nFileOffset = 0
DateiDialogStruktur.nFileExtension = 0
DateiDialogStruktur.lCustData = 0
DateiDialogStruktur.lpfnHook = 0
DateiDialogStruktur.lpTemplateName = &quot;&quot;
&nbsp;
Rueckwerte = GetSaveFileName(DateiDialogStruktur)
&nbsp;
<span class="TOKEN">If</span> Rueckwerte &lt;&gt; 0 <span class="TOKEN">Then</span>
DateiSpeichern = Left(DateiDialogStruktur.lpstrFile, _
InStr(DateiDialogStruktur.lpstrFile, Chr$(0)) - 1)
<span class="TOKEN">End</span> <span class="TOKEN">If</span>
&nbsp;
Exit_DateiSpeichern:
<span class="TOKEN">Exit Function</span>
&nbsp;
Err_DateiSpeichern:
MsgBox Err.Description
<span class="TOKEN">Resume</span> Exit_DateiSpeichern
&nbsp;
<span class="TOKEN">End</span> <span class="TOKEN">Function</span></pre></div>

Zum Öffnen verwenden Sie innerhalb Ihres Formulars den folgenden Code:

<div><link href="http://www.ms-office-forum.net/forum/externals/codeconv.css" rel="stylesheet"><pre><span class="TOKEN">Dim</span> Path <span class="TOKEN">As</span> <span class="TOKEN">String</span>
&nbsp;
Path = DateiOeffnen(&quot;C:\Eigene Dateien&quot;, &quot;Datei &ouml;ffnen&quot;)
MsgBox Path</pre></div>

Zum Speichern einer Datei verwenden Sie den folgenden Code:

<div><link href="http://www.ms-office-forum.net/forum/externals/codeconv.css" rel="stylesheet"><pre><span class="TOKEN">Dim</span> Path <span class="TOKEN">As</span> <span class="TOKEN">String</span>
&nbsp;
Path = DateiSpeichern(&quot;C:\Eigene Dateien&quot;, &quot;Datei speichern&quot;)
MsgBox Path</pre></div>

Sascha Trowitzsch
06.02.2005, 18:04
Ab Access2000 kann man sich die (lange) API-Lösung sparen und zum Öffnen einer Datei der undokumentierten Access-Klasse Wizhook bedienen:
<div><link href="http://www.ms-office-forum.net/forum/externals/codeconv.css" rel="stylesheet"><pre><span class="REM">'Ab A2000:</span>
<span class="TOKEN">Function</span> OpenFileName(<span class="TOKEN">Optional</span> StartDir <span class="TOKEN">As</span> String, _
<span class="TOKEN">Optional</span> sTitle <span class="TOKEN">As</span> <span class="TOKEN">String</span> = &quot;Datei ausw&auml;hlen:&quot;, _
<span class="TOKEN">Optional</span> sFilter <span class="TOKEN">As</span> <span class="TOKEN">String</span> = &quot;Access-DB (*.mdb)|Alle Dateien (*.*)&quot;) <span class="TOKEN">As</span> <span class="TOKEN">String</span>
<span class="TOKEN">Static</span> sDir <span class="TOKEN">As</span> <span class="TOKEN">String</span>
&nbsp;
WizHook.Key = 51488399
<span class="TOKEN">If</span> Len(StartDir) = 0 <span class="TOKEN">Then</span>
<span class="TOKEN">If</span> Len(sDir) = 0 <span class="TOKEN">Then</span>
StartDir = CurrentProject.Path
<span class="TOKEN">Else</span>
StartDir = sDir
<span class="TOKEN">End</span> <span class="TOKEN">If</span>
<span class="TOKEN">End</span> <span class="TOKEN">If</span>
<span class="TOKEN">Call</span> WizHook.GetFileName(Application.hWndAccessApp, _
&quot;Microsoft Access&quot;, sTitle, _
&quot;&Ouml;ffnen&quot;, OpenFileName, _
StartDir, sFilter, _
0&amp;, 0&amp;, &amp;H40, <span class="TOKEN">True</span>)
<span class="TOKEN">If</span> Len(OpenFileName) &gt; 0 <span class="TOKEN">Then</span>
sDir = <span class="TOKEN">Left</span>(OpenFileName, InStrRev(OpenFileName, &quot;\&quot;, , vbTextCompare))
<span class="TOKEN">End</span> <span class="TOKEN">If</span>
<span class="TOKEN">End</span> <span class="TOKEN">Function</span><hr></pre></div>

Der Vollständigkeit halber hier noch ein analoger Code für den ab AXP eingebauten FileDialog - obwohl es mit dem WizHook-Code wegen des einfachen Filter-Strings einfacher geht:
<div><link href="http://www.ms-office-forum.net/forum/externals/codeconv.css" rel="stylesheet"><pre><span class="REM">'AXP ff.:</span>
<span class="TOKEN">Public Function</span> OpenFileNameAX(<span class="TOKEN">Optional</span> StartDir <span class="TOKEN">As</span> String, _
<span class="TOKEN">Optional</span> sTitle <span class="TOKEN">As</span> <span class="TOKEN">String</span> = &quot;Datei ausw&auml;hlen:&quot;, _
<span class="TOKEN">Optional</span> sFilter <span class="TOKEN">As</span> <span class="TOKEN">String</span> = &quot;Access-Datenbank (*.mdb)|Alle Dateien (*.*)&quot;) <span class="TOKEN">As</span> <span class="TOKEN">String</span>
<span class="TOKEN">Dim</span> clsDialog <span class="TOKEN">As</span> Office.FileDialog
<span class="TOKEN">Dim</span> vFilter <span class="TOKEN">As</span> Variant, i <span class="TOKEN">As</span> <span class="TOKEN">Long</span>
<span class="TOKEN">Dim</span> strExt <span class="TOKEN">As</span> String, sDescr <span class="TOKEN">As</span> <span class="TOKEN">String</span>
&nbsp;
<span class="TOKEN">Set</span> clsDialog = Application.FileDialog(msoFileDialogFilePicker)
<span class="TOKEN">With</span> clsDialog
.Title = sTitle
.InitialFileName = StartDir
.AllowMultiSelect = <span class="TOKEN">False</span>
.ButtonName = &quot;OK&quot;
.InitialView = msoFileDialogViewList
<span class="TOKEN">If</span> sFilter &lt;&gt; &quot;&quot; <span class="TOKEN">Then</span>
.Filters.Clear
vFilter = Split(sFilter, &quot;|&quot;)
<span class="TOKEN">For</span> i = 0 <span class="TOKEN">To</span> <span class="TOKEN">UBound</span>(vFilter)
strExt = <span class="TOKEN">Trim</span>(<span class="TOKEN">Mid</span>(vFilter(i), InStrRev(vFilter(i), &quot;(&quot;) + 1))
<span class="TOKEN">If</span> <span class="TOKEN">Right</span>(strExt, 1) = &quot;)&quot; <span class="TOKEN">Then</span> strExt = <span class="TOKEN">Trim</span>(<span class="TOKEN">Left</span>(strExt, Len(strExt) - 1))
sDescr = <span class="TOKEN">Trim</span>(<span class="TOKEN">Left</span>(vFilter(i), InStrRev(vFilter(i), &quot;(&quot;) - 1))
.Filters.Add sDescr, strExt
<span class="TOKEN">Next</span> i
<span class="TOKEN">Else</span>
.Filters.Add &quot;Access-Datenbank&quot;, &quot;*.mdb;*.mde&quot;
<span class="TOKEN">End</span> <span class="TOKEN">If</span>
<span class="TOKEN">If</span> .Show <span class="TOKEN">Then</span> OpenFileNameAX = .SelectedItems(1)
<span class="TOKEN">End</span> <span class="TOKEN">With</span>
&nbsp;
<span class="TOKEN">End</span> <span class="TOKEN">Function</span><hr></pre></div>

Ciao, Sascha

SkipperUwe
16.11.2006, 12:26
Hallo Sascha!

Dein Vorschlag gefällt mir, jedoch benötige ich statt msoFileDialogFilePicker die Option msoFileDialogSaveAs.
Wird dann
Set clsDialog = Application.FileDialog(msoFileDialogSaveAs)
ausgeführt, so gibt Access das folgenden Fehlerfenster aus:

Microsoft Visual Basic
Laufzeitfehler '445':
Objekt unterstützt diese Aktion nicht


Für einen Tip wäre ich dankbar

Linus1971
19.11.2006, 20:42
Hallo,

Du solltest Deine Frage vielleicht im Access Forum (http://ms-office-forum.de/forum/forumdisplay.php?f=60) stellen und dort Bezug auf diesen Thread hier nehmen. Im Forum wird Deine Frage vielleicht noch schneller beantwortet.

Ausserdem sollten hier im Code-Archiv keine Fragen gestellt werden.