Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Dialog Box


Message #1 by "Kenneth Mungwira" <KennethMungwira@Y...> on Thu, 30 May 2002 14:06:53
Can anyone help with this code, which is behind a command button, to 
choose "*.mdb" in the directory of my choosing.

Private Sub cmdFileOpen_Click()
    Dim strFilter As String
    Dim varReturn As Variant
    Dim lngFlags As Long
    lngFlags = glrOFN_HIDEREADONLY Or glrOFN_EXTENSIONDIFFERENT
      
    strFilter = glrAddFilterItem(strFilter, "Jet Database Files 
(*.mdb)", "*.MDB")
    varReturn = glrCommonFileOpenSave(InitialDir:=CurDir(), _
      Filter:=strFilter, FilterIndex:=1, Flags:=lngFlags, _
      DialogTitle:="Selecting a Jet Database File", Hwnd:=Me.Hwnd)
    If Not IsNull(varReturn) Then
        Me![txtLDBFilePath] = varReturn
    End If
End Sub
Message #2 by "Jonathan R. Els" <jonathan.els@f...> on Thu, 30 May 2002 16:03:20 +0200
I'm having a similar problem.

-----Original Message-----
From: Kenneth Mungwira [mailto:KennethMungwira@Y...] 
Sent: 30 May 2002 14:07
To: Access
Subject: [access] Dialog Box


Can anyone help with this code, which is behind a command button, to 
choose "*.mdb" in the directory of my choosing.

Private Sub cmdFileOpen_Click()
    Dim strFilter As String
    Dim varReturn As Variant
    Dim lngFlags As Long
    lngFlags = glrOFN_HIDEREADONLY Or glrOFN_EXTENSIONDIFFERENT
      
    strFilter = glrAddFilterItem(strFilter, "Jet Database Files 
(*.mdb)", "*.MDB")
    varReturn = glrCommonFileOpenSave(InitialDir:=CurDir(), _
      Filter:=strFilter, FilterIndex:=1, Flags:=lngFlags, _
      DialogTitle:="Selecting a Jet Database File", Hwnd:=Me.Hwnd)
    If Not IsNull(varReturn) Then
        Me![txtLDBFilePath] = varReturn
    End If
End Sub



Message #3 by "John Ruff" <papparuff@c...> on Thu, 30 May 2002 09:05:30 -0700
Kenneth and Jonathan,

It looks like this is the File Open/Save Dialog Box from Dev Ashish's
web-site.  I changed the name of your constants to that from Dev's
web-site and it works fine in my db.  Your code is Remarked out and
replaced with the appropriate constants for the File Open/Save Dialog
Box code from Dev's web-site

    Dim strFilter As String
    Dim varReturn As Variant
    Dim lngFlags As Long
    
    ' These are bad constant names
'    lngFlags = glrOFN_HIDEREADONLY Or glrOFN_EXTENSIONDIFFERENT
    lngFlags = ahtOFN_HIDEREADONLY Or ahtOFN_EXTENSIONDIFFERENT
      
    ' This is a bad constant name
'    strFilter = glrAddFilterItem(strFilter, "Jet Database Files
(*.mdb)", "*.MDB")
    strFilter = ahtAddFilterItem(strFilter, "Jet Database Files
(*.mdb)", "*.MDB")
'    varReturn = glrCommonFileOpenSave(InitialDir:=CurDir(),
    varReturn = ahtCommonFileOpenSave(InitialDir:=CurDir(), _
      Filter:=strFilter, FilterIndex:=1, Flags:=lngFlags, _
      DialogTitle:="Selecting a Jet Database File", hwnd:=Me.hwnd)
    If Not IsNull(varReturn) Then
        txtLDBFilePath = varReturn
    End If

John Ruff - The Eternal Optimist :-)
Always Looking for a Contract Opportunity

xxx.xxx.xxxx
9306 Farwest Dr SW
Lakewood, WA 98498 


-----Original Message-----
From: Kenneth Mungwira [mailto:KennethMungwira@Y...] 
Sent: Thursday, May 30, 2002 2:07 PM
To: Access
Subject: [access] Dialog Box

Can anyone help with this code, which is behind a command button, to 
choose "*.mdb" in the directory of my choosing.

Private Sub cmdFileOpen_Click()
    Dim strFilter As String
    Dim varReturn As Variant
    Dim lngFlags As Long
    lngFlags = glrOFN_HIDEREADONLY Or glrOFN_EXTENSIONDIFFERENT
      
    strFilter = glrAddFilterItem(strFilter, "Jet Database Files 
(*.mdb)", "*.MDB")
    varReturn = glrCommonFileOpenSave(InitialDir:=CurDir(), _
      Filter:=strFilter, FilterIndex:=1, Flags:=lngFlags, _
      DialogTitle:="Selecting a Jet Database File", Hwnd:=Me.Hwnd)
    If Not IsNull(varReturn) Then
        Me![txtLDBFilePath] = varReturn
    End If
End Sub

Message #4 by "Kenneth Mungwira" <KennethMungwira@Y...> on Thu, 30 May 2002 19:11:06
Dear John,

When I run your adjusted code I get the Error - Variable Not Defined -
 "ahtOFH_HIDEREADONLY.
Please help.

Thank you 


> Kenneth and Jonathan,

It looks like this is the File Open/Save Dialog Box from Dev Ashish's
web-site.  I changed the name of your constants to that from Dev's
web-site and it works fine in my db.  Your code is Remarked out and
replaced with the appropriate constants for the File Open/Save Dialog
Box code from Dev's web-site

    Dim strFilter As String
    Dim varReturn As Variant
    Dim lngFlags As Long
    
    ' These are bad constant names
'    lngFlags = glrOFN_HIDEREADONLY Or glrOFN_EXTENSIONDIFFERENT
    lngFlags = ahtOFN_HIDEREADONLY Or ahtOFN_EXTENSIONDIFFERENT
      
    ' This is a bad constant name
'    strFilter = glrAddFilterItem(strFilter, "Jet Database Files
(*.mdb)", "*.MDB")
    strFilter = ahtAddFilterItem(strFilter, "Jet Database Files
(*.mdb)", "*.MDB")
'    varReturn = glrCommonFileOpenSave(InitialDir:=CurDir(),
    varReturn = ahtCommonFileOpenSave(InitialDir:=CurDir(), _
      Filter:=strFilter, FilterIndex:=1, Flags:=lngFlags, _
      DialogTitle:="Selecting a Jet Database File", hwnd:=Me.hwnd)
    If Not IsNull(varReturn) Then
        txtLDBFilePath = varReturn
    End If

John Ruff - The Eternal Optimist :-)
Always Looking for a Contract Opportunity

xxx.xxx.xxxx
9306 Farwest Dr SW
Lakewood, WA 98498 


-----Original Message-----
From: Kenneth Mungwira [mailto:KennethMungwira@Y...] 
Sent: Thursday, May 30, 2002 2:07 PM
To: Access
Subject: [access] Dialog Box

Can anyone help with this code, which is behind a command button, to 
choose "*.mdb" in the directory of my choosing.

Private Sub cmdFileOpen_Click()
    Dim strFilter As String
    Dim varReturn As Variant
    Dim lngFlags As Long
    lngFlags = glrOFN_HIDEREADONLY Or glrOFN_EXTENSIONDIFFERENT
      
    strFilter = glrAddFilterItem(strFilter, "Jet Database Files 
(*.mdb)", "*.MDB")
    varReturn = glrCommonFileOpenSave(InitialDir:=CurDir(), _
      Filter:=strFilter, FilterIndex:=1, Flags:=lngFlags, _
      DialogTitle:="Selecting a Jet Database File", Hwnd:=Me.Hwnd)
    If Not IsNull(varReturn) Then
        Me![txtLDBFilePath] = varReturn
    End If
End Sub

Message #5 by "John Ruff" <papparuff@c...> on Thu, 30 May 2002 11:14:30 -0700
OK,

Where is glrOFN_HIDEREADONLY defined?  What module?

John Ruff - The Eternal Optimist :-)
Always Looking for a Contract Opportunity

xxx.xxx.xxxx
9306 Farwest Dr SW
Lakewood, WA 98498 


-----Original Message-----
From: Kenneth Mungwira [mailto:KennethMungwira@Y...] 
Sent: Thursday, May 30, 2002 7:11 PM
To: Access
Subject: [access] RE: Dialog Box

Dear John,

When I run your adjusted code I get the Error - Variable Not Defined -
 "ahtOFH_HIDEREADONLY.
Please help.

Thank you 


> Kenneth and Jonathan,

It looks like this is the File Open/Save Dialog Box from Dev Ashish's
web-site.  I changed the name of your constants to that from Dev's
web-site and it works fine in my db.  Your code is Remarked out and
replaced with the appropriate constants for the File Open/Save Dialog
Box code from Dev's web-site

    Dim strFilter As String
    Dim varReturn As Variant
    Dim lngFlags As Long
    
    ' These are bad constant names
'    lngFlags = glrOFN_HIDEREADONLY Or glrOFN_EXTENSIONDIFFERENT
    lngFlags = ahtOFN_HIDEREADONLY Or ahtOFN_EXTENSIONDIFFERENT
      
    ' This is a bad constant name
'    strFilter = glrAddFilterItem(strFilter, "Jet Database Files
(*.mdb)", "*.MDB")
    strFilter = ahtAddFilterItem(strFilter, "Jet Database Files
(*.mdb)", "*.MDB")
'    varReturn = glrCommonFileOpenSave(InitialDir:=CurDir(),
    varReturn = ahtCommonFileOpenSave(InitialDir:=CurDir(), _
      Filter:=strFilter, FilterIndex:=1, Flags:=lngFlags, _
      DialogTitle:="Selecting a Jet Database File", hwnd:=Me.hwnd)
    If Not IsNull(varReturn) Then
        txtLDBFilePath = varReturn
    End If

John Ruff - The Eternal Optimist :-)
Always Looking for a Contract Opportunity

xxx.xxx.xxxx
9306 Farwest Dr SW
Lakewood, WA 98498 


-----Original Message-----
From: Kenneth Mungwira [mailto:KennethMungwira@Y...] 
Sent: Thursday, May 30, 2002 2:07 PM
To: Access
Subject: [access] Dialog Box

Can anyone help with this code, which is behind a command button, to 
choose "*.mdb" in the directory of my choosing.

Private Sub cmdFileOpen_Click()
    Dim strFilter As String
    Dim varReturn As Variant
    Dim lngFlags As Long
    lngFlags = glrOFN_HIDEREADONLY Or glrOFN_EXTENSIONDIFFERENT
      
    strFilter = glrAddFilterItem(strFilter, "Jet Database Files 
(*.mdb)", "*.MDB")
    varReturn = glrCommonFileOpenSave(InitialDir:=CurDir(), _
      Filter:=strFilter, FilterIndex:=1, Flags:=lngFlags, _
      DialogTitle:="Selecting a Jet Database File", Hwnd:=Me.Hwnd)
    If Not IsNull(varReturn) Then
        Me![txtLDBFilePath] = varReturn
    End If
End Sub


Message #6 by Kenneth Mungwira <kennethmungwira@y...> on Thu, 30 May 2002 11:58:12 -0700 (PDT)
--0-1654793378-1022785092=:85745
Content-Type: text/plain; charset=us-ascii


 Module information requested.
  Option Compare Database
Option Explicit
' Note: This code is from the Access 95 Developer's Handbook,
' by Paul Litwin, Ken Getz, Mike Gilbert, and Greg Reddick.
' (c) 1995 by Sybex.
' Used with permission

Type tagOPENFILENAME
     lStructSize As Long
     hwndOwner As Long
     hInstance As Long
     strFilter As String
     strCustomFilter As String
     nMaxCustFilter As Long
     nFilterIndex As Long
     strFile As String
     nMaxFile As Long
     strFileTitle As String
     nMaxFileTitle As Long
     strInitialDir As String
     strTitle As String
     Flags As Long
     nFileOffset As Integer
     nFileExtension As Integer
     strDefExt As String
     lCustData As Long
     lpfnHook As Long
     lpTemplateName As String
End Type
Declare Function glr_apiGetOpenFileName Lib "comdlg32.dll" _
 Alias "GetOpenFileNameA" (ofn As tagOPENFILENAME) As Boolean
Declare Function glr_apiGetSaveFileName Lib "comdlg32.dll" _
 Alias "GetSaveFileNameA" (ofn As tagOPENFILENAME) As Boolean
Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
Public Const glrOFN_READONLY = &H1
Public Const glrOFN_OVERWRITEPROMPT = &H2
Public Const glrOFN_HIDEREADONLY = &H4
Public Const glrOFN_NOCHANGEDIR = &H8
Public Const glrOFN_SHOWHELP = &H10
Public Const glrOFN_NOVALIDATE = &H100
Public Const glrOFN_ALLOWMULTISELECT = &H200
Public Const glrOFN_EXTENSIONDIFFERENT = &H400
Public Const glrOFN_PATHMUSTEXIST = &H800
Public Const glrOFN_FILEMUSTEXIST = &H1000
Public Const glrOFN_CREATEPROMPT = &H2000
Public Const glrOFN_SHAREAWARE = &H4000
Public Const glrOFN_NOREADONLYRETURN = &H8000
Public Const glrOFN_NOTESTFILECREATE = &H10000
Public Const glrOFN_NONETWORKBUTTON = &H20000
Public Const glrOFN_NOLONGNAMES = &H40000
Public Const glrOFN_EXPLORER = &H80000
Public Const glrOFN_NODEREFERENCELINKS = &H100000
Public Const glrOFN_LONGNAMES = &H200000
Function glrCommonFileOpenSave( _
 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 OpenFile As Variant, _
 Optional ByVal Hwnd 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 glrOFN_* 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.
    '    OpenFile: Boolean(True=Open File/False=Save As)
    '    Handle of window to act as parent to the dialog.
    ' 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 = ""
    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(OpenFile) Then OpenFile = True
    If IsMissing(Hwnd) Then Hwnd = Application.hWndAccessApp
    
    ' 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 = CurDir
        ' Didn't think most people would want to deal with
        ' these options.
        .hInstance = 0
        .strCustomFilter = ""
        .nMaxCustFilter = 0
        .lpfnHook = 0
    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 = glr_apiGetOpenFileName(ofn)
    Else
        fResult = glr_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
        glrCommonFileOpenSave = glrTrimNull(ofn.strFile)
    Else
        glrCommonFileOpenSave = Null
    End If
End Function
Function glrAddFilterItem(strFilter As String, _
 strDescription As String, Optional varItem As Variant) As String
    ' Tack a new chunk onto the file filter.
    ' That is, take the old value, stick onto it the description,
    ' (like "Databases"), a null character, the skeleton
    ' (like "*.mdb;*.mda") and a final null character.
    If IsMissing(varItem) Then varItem = "*.*"
    glrAddFilterItem = strFilter & _
     strDescription & vbNullChar & _
     varItem & vbNullChar
End Function
Function glrTrimNull(ByVal strItem As String) As String
    Dim intPos As Integer
    intPos = InStr(strItem, vbNullChar)
    If intPos > 0 Then
        glrTrimNull = Left(strItem, intPos - 1)
    Else
        glrTrimNull = strItem
    End If
End Function
    
 



---------------------------------
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup

  Return to Index