Solved

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

Posted on 2002-03-12
4
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

691 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