Solved

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

Posted on 2002-03-12
4
271 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 10; WInload.exe / endless auto repair 7 124
hp envy 4500 driver installation problem 5 68
Mac OS 10.7.5 upgrade 3 46
Set WorkSheet  not Working 9 44
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you don't know how to downgrade, my instructions below should be helpful.
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…

821 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