Solved

File Chooser - want to make a form "return" a file name

Posted on 2002-03-12
4
270 Views
Last Modified: 2013-11-13
I'm sure some one has done this before... what I want to have is a button called "Open File" on my main form. I want it so that when I hit this button it loads the "File Chooser" form and lets the user select a file

What I REALLY want though is for the form to return the file name (or a -1 for a fail. However, forms, to the best of my knowledge don't have returns... I have currently got around this by creating a driver function that waits for the user to select a file or cancels... when the user makes a choice the function closes the form and returns either the file name or a -1 to indicate no file chosen.

Any tips or code GREATLY appreciated...
0
Comment
Question by:woottond
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
hes earned 100 total points
ID: 6857452
Why not use the commonDialog
This example lets the user select multiple graphic files, the commondialog is named cdFiles

cdFiles.Filter = "Graphic Files|*.gif;*.jpg;*.bmp;"
  cdFiles.Flags = cdlOFNAllowMultiselect
  cdFiles.ShowOpen
  If cdFiles.FileName <> "" Then
   ' get file names selected
    lsFiles = Split(cdFiles.FileName, Chr(32))
  else
   ' no files were selected
  End If

Remove the .Flages if you only want to allow 1 selected
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 6857464
Make a public variable on the calling (main) form and then set the value from the called form.
Ex: (Main Form named Form1)
Option Explicit
Public sFN as string

called form (Form2)

Form1.sFN = "Any Value"

Now Form1 can reference the variable sFN as can Form2...
0
 

Author Comment

by:woottond
ID: 6857549
Thanks hes!

I made a mistake and missed that dialog box - had a funny feeling when I was writing the form that I was doing it the hard way - and that it was weird that there wasn't a dialog box already...

THANKS!!!

btw - trkcorp - I was doing something quite simular before, like what you had suggested - The problem is you have to know when the file has been choosen, which means you must setup some kinda waitFor event... which was the part I had problems with (code wise its easy - I just don't like it...)
0
 

Author Comment

by:woottond
ID: 6857560
Fast, Concise, Easy

(took 10 minutes!!!)

Thanks Hes
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question