Solved

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

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

One of the most frequently asked questions on EE in the "Windows Installer" zone is how to eliminate self-triggered installation of some product.  The problem occurs when, suddenly, whenever a certain application is launched, or even when a folder i…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now