Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2002-03-12
4
Medium Priority
?
275 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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
Suggested Courses

636 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