PDA

Vollständige Version anzeigen : Problem mit VBA code


dmsman
03.07.2001, 13:50
Hallo,
bei klick auf einen button wird selectdoku(im modul) aufgerufen.
diese startet den api-dialog für datei-öffnen.ok dann wähle ich die datei aus startet er die von mir angegebene msgbox und zeigt nochmal den dateinamen an und frägt mich ob einstellungen stimmen bei ja soll er ein anderes formular: frmDoku_Aufnahme_2 starten ! macht er aber nicht!
Er startet wieder den Dialog aber egal was man drückt, danach kommt erst das verlangte formular ! wieso öffnet er nicht gleich beim Ja-Fall das Formular ?
unten ist der komplette code aufgeführt!danke


Function SelectDoku()
Dim strFilter As String
Dim lngFlags As Long
Dim var, ant As String
Dim SaveFileName As String 'variable für vollständige dateiangabe mit pfad
var = CurrentUser()

'strFilter ruft wieder eine Funktion namens ahtAddFilterItem auf
strFilter = ahtAddFilterItem(strFilter, "Exe Dateien (*.exe)", "*.EXE")
strFilter = ahtAddFilterItem(strFilter, "Text Dateien (*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "Word Dateien (*.doc)", "*.DOC")
strFilter = ahtAddFilterItem(strFilter, "Excel Dateien (*.xls)", "*.XLS")
'strFilter = ahtAddFilterItem(strFilter, "MP3 Dateien (*.mp3)", "*.MP3")
strFilter = ahtAddFilterItem(strFilter, "Access Dateien (*.mda, *.mdb)", "*.MDA;*.MDB")
strFilter = ahtAddFilterItem(strFilter, "Zip Dateien (*.zip)", "*.ZIP")
strFilter = ahtAddFilterItem(strFilter, "Alle Dateien (*.*)", "*.*")

SaveFileName = ahtCommonFileOpenSave(InitialDir:="C:\", Filter:=strFilter, FilterIndex:=7, Flags:=lngFlags, DialogTitle:="Dokument auswählen")

If MsgBox("Sie haben folgenden Datei ausgewählt: " & vbCrLf & SaveFileName & vbCrLf & "Sind Sie sicher daß es die Datei ist ?", vbYesNo + vbQuestion, "Info") = vbYes Then
'Ja gedrückt:
'MsgBox ("ok file selected!")
DoCmd.OpenForm "frmDoku_Aufnahme_2"

Else
'Nein
'DoCmd.close
MsgBox ("Neinfall")
'SelectDoku
End If

'Debug.Print Hex(lngFlags)

End Function


Function ahtAddFilterItem(strFilter As String, _
strDescription As String, Optional varItem As Variant) As String

If IsMissing(varItem) Then varItem = "*.*"
ahtAddFilterItem = strFilter & _
strDescription & vbNullChar & _
varItem & vbNullChar
End Function

Private Function TrimNull(ByVal strItem As String) As String
Dim intPos As Integer
intPos = InStr(strItem, vbNullChar)
If intPos > 0 Then
TrimNull = Left(strItem, intPos - 1)
Else
TrimNull = strItem
End If
End Function
Function ahtCommonFileOpenSave( _
Optional ByRef Flags As Variant, _
Optional ByVal InitialDir As Variant, _
Optional ByVal Filter As Variant, _
Optional ByVal FilterIndex As Variant, _
Optional ByVal DefaultExt As Variant, _
Optional ByVal FileName As Variant, _
Optional ByVal DialogTitle As Variant, _
Optional ByVal hwnd As Variant, _
Optional ByVal OpenFile As Variant) As Variant
' This is the entry point you'll use to call the common
' file open/save dialog. The parameters are listed
' below, and all are optional.
'
' In:
' Flags: one or more of the ahtOFN_* constants, OR'd together.
' InitialDir: the directory in which to first look
' Filter: a set of file filters, set up by calling
' AddFilterItem. See examples.
' FilterIndex: 1-based integer indicating which filter
' set to use, by default (1 if unspecified)
' DefaultExt: Extension to use if the user doesn't enter one.
' Only useful on file saves.
' FileName: Default value for the file name text box.
' DialogTitle: Title for the dialog.
' hWnd: parent window handle
' OpenFile: Boolean(True=Open File/False=Save As)
' Out:
' Return Value: Either Null or the selected filename
Dim OFN As tagOPENFILENAME
Dim strFilename As String
Dim strFileTitle As String
Dim fResult As Boolean
' Give the dialog a caption title.
If IsMissing(InitialDir) Then InitialDir = CurDir
If IsMissing(Filter) Then Filter = ""
If IsMissing(FilterIndex) Then FilterIndex = 1
If IsMissing(Flags) Then Flags = 0&
If IsMissing(DefaultExt) Then DefaultExt = ""
If IsMissing(FileName) Then FileName = ""
If IsMissing(DialogTitle) Then DialogTitle = ""
If IsMissing(hwnd) Then hwnd = Application.hWndAccessApp
If IsMissing(OpenFile) Then OpenFile = True
' Allocate string space for the returned strings.
strFilename = Left(FileName & String(256, 0), 256)
strFileTitle = String(256, 0)
' Set up the data structure before you call the function
With OFN
.lStructSize = Len(OFN)
.hwndOwner = hwnd
.strFilter = Filter
.nFilterIndex = FilterIndex
.strFile = strFilename
.nMaxFile = Len(strFilename)
.strFileTitle = strFileTitle
.nMaxFileTitle = Len(strFileTitle)
.strTitle = DialogTitle
'.Flags = Flags
.strDefExt = DefaultExt
.strInitialDir = InitialDir
' Didn't think most people would want to deal with
' these options.
.hInstance = 0
'.strCustomFilter = ""
'.nMaxCustFilter = 0
.lpfnHook = 0
'New for NT 4.0
.strCustomFilter = String(255, 0)
.nMaxCustFilter = 255
End With
' This will pass the desired data structure to the
' Windows API, which will in turn it uses to display
' the Open/Save As Dialog.
If OpenFile Then
fResult = aht_apiGetOpenFileName(OFN)
Else
fResult = aht_apiGetSaveFileName(OFN)
End If

' The function call filled in the strFileTitle member
' of the structure. You'll have to write special code
' to retrieve that if you're interested.
If fResult Then
' You might care to check the Flags member of the
' structure to get information about the chosen file.
' In this example, if you bothered to pass in a
' value for Flags, we'll fill it in with the outgoing
' Flags value.
If Not IsMissing(Flags) Then Flags = OFN.Flags
ahtCommonFileOpenSave = TrimNull(OFN.strFile)
Else
ahtCommonFileOpenSave = vbNullString
End If
' **************** Code End ***********************************
End Function

Kurt aus Kienitz
03.07.2001, 14:09
Hallo,

Das liegt daran, daß die Ausführung des Codes beim DoCmd.OpenForm nicht angehalten wird.

Was Du willst ist (glaube ich :)) den Ausgangsdialog solange anzuhalten bis der Sub-Dialog abgearbeitet wurde.
Dann probier mal folgendes aus:

DoCmd.OpenForm "frmDoku_Aufnahme_2", , , , , acDialog

HTH

dmsman
03.07.2001, 14:16
sorry fürs posten hat sich schon erledigt!