Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

making objects visible or not when using automation

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
I am working with a process that allows automation. It has a very poor file browser and I would like to pop the Windows file browser I use in some Access applications. I can get the Access to work but with some problems. Can any one help me with these? The code is below for reference if anyone needs it.

A. Is there a better way to invoke the function than using Eval? It seems very slow.

B. I make it visible just before I call it, but it comes up in odd sizes and then the File Browser opens inside that. I know I can check Application.Visible within the automation code, but how do I set it visible within the automation code just before it pops up the browser?

C. Can I size the automation screen to the size of the browser window or at least make it look like something before I make it visible?

D. How do I center the File browser window on the screen?

Thanks in advance for any help or suggestions!

Have a great day!

Public Function GetFileName2()
Dim strFileName As String
Dim strPath As String
Dim appAccess As Access.Application
Set appAccess = New Access.Application
appAccess.OpenCurrentDatabase _
"c:\Temp\GetFileName.mdb"
appAccess.Visible = True
strFileName = appAccess.Eval("PopFileBrowser()")
appAccess.Visible = False
appAccess.CloseCurrentDatabase
Set appAccess = Nothing
GetFileName2 = strFileName
Exit Function
 
What is "PopFileBrowser()"? I can't find it in Access or on the web.
 
try something like this instead

Code:
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type
Private Sub Form_Load()
    'KPD-Team 1998
    'URL: [URL unfurl="true"]http://www.allapi.net/[/URL]
    'E-Mail: KPDTeam@Allapi.net
    Dim OFName As OPENFILENAME
    OFName.lStructSize = Len(OFName)
    'Set the parent window
    OFName.hwndOwner = Me.hWnd
    'Set the application's instance
    OFName.hInstance = App.hInstance
    'Select a filter
    OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
    'create a buffer for the file
    OFName.lpstrFile = Space$(254)
    'set the maximum length of a returned file
    OFName.nMaxFile = 255
    'Create a buffer for the file title
    OFName.lpstrFileTitle = Space$(254)
    'Set the maximum length of a returned file title
    OFName.nMaxFileTitle = 255
    'Set the initial directory
    OFName.lpstrInitialDir = "C:\"
    'Set the title
    OFName.lpstrTitle = "Open File - KPD-Team 1998"
    'No flags
    OFName.flags = 0

    'Show the 'Open File'-dialog
    If GetOpenFileName(OFName) Then
        MsgBox "File to Open: " + Trim$(OFName.lpstrFile)
    Else
        MsgBox "Cancel was pressed"
    End If
End Sub
 
Zathras,

Sorry for the miscommunication, PopFileBrowser is just a wrap-a-round function I wrote which calls the Windows file browser with options which I usually use.

Have a great day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top