Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browsing Hard Drive

Status
Not open for further replies.

icupat

Technical User
Aug 6, 2002
25
CA
I would like to be able to click on a command button that allows you to browse for a file to link to. So clicking on the command button brings up a windows explorer window and then this link is sent as a hyperlink to a text box.

Thanks guys. This is a great forum, already a lot of help and only known about it for 2 days.
 
To do what you want, you need to insert the ActiveX commondialog control onto the form. Then, on the OnClick event of the Browse button (you create), insert the following code (you will need to modify it to suit your needs)
Code:
    On Error GoTo ErrHandler
        

'******************************************************************************************
'*  The following CommonDialog properties can be set via the Custom property dialog box.
'*  They are set here in case the custom property is overwritten for some reason.
'******************************************************************************************

    dlgBrowse.CancelError = True
    
    dlgBrowse.DialogTitle = "Select Job Class output file"
    dlgBrowse.InitDir = "c:\dev\"
    dlgBrowse.FileName = "ADefaultName.txt"
    dlgBrowse.Filter = "JobClass (JobClass*.txt)|JobClass*.txt|Text (*.txt)|*.txt|All Files (*.*)|*.*"
    dlgBrowse.DefaultExt = "txt"
    
    dlgBrowse.FilterIndex = 1
    dlgBrowse.Flags = 0
    dlgBrowse.MaxFileSize = 260
            
    
    dlgBrowse.ShowOpen
            
    If (Len(dlgBrowse.FileName) > 0) Then
        
        txtOutputFile_JobClass = dlgBrowse.FileName
        
    End If

ExitProcedure:
    
    Exit Function

ErrHandler:

    If (Err <> cdlCancel) Then
        msgbox err.number & err.description
    End If

    Resume ExitProcedure
 
Also, for the original poster and others:

You may not have the Common Dialog Control available to you. If it didn't come with some other package you have purchased, it's not there. Earlier this Spring or Summer, I spent a little while searching for it on my machine -- having known of the control from work with Visual Studio 97 -- when I found out the control does not come with Access 97.

So, if you don't have the Common Dialog Control available for design-time use, are you stuck? NO! The Common Dialog itself is a part of every Windows system that's been put out for years. And you can get to it and use it through the Windows API (Application Programming Interface).

&quot;API&quot; is just the (for some folks) scary term for &quot;other subs and functions we can use in our programs&quot;. The only part that requires extra effort is finding out what subs and functions exist and how they are supposed to be used. So &quot;API&quot; shouldn't be a scary term for programmers anymore. If you can program in a given language, you can program with the APIs as easily, once you find them and declare them in your own code.

There are articles here in Tek-Tips that give you the VBA code you need to use the common dialog (which gives you 'Open', 'Save', 'Save As', 'Color', and others) in Access modules. Search for 'Common Dialog'. (???It might even be in this forum's FAQ???)

If you do not yet program with VBA, then there is more for you to do. Find someone who does, to use the code for you... Use this as an excuse to learn some VBA... I don't off-hand know of any way for you to get the functionality you want without *some* programming, if you don't have the Common Dialog control available to drop straight onto your form.

And by the way... How is the Common Dialog used? On a very high level: 1) The Common Dialog is started. 2) The user &quot;does the stuff that the user does&quot; with the Common Dialog. 3) The Common Dialog returns a string, which is the path and filename of the file chosen by the user. That behavior is the same for 'Open', 'Save', and 'Save As'. Even if the filename chosen by the user is the name of a file that doesn't yet exist, that's the string returned by the Common Dialog. Your job as the programmer is to capture that string and deal with it well.

In icupat's case, it sounds like icupat wants to put the returned string into a textbox on a form. I admit that I'm not sure what precisely is meant by &quot;this link is sent as a hyperlink to a text box&quot;. If that means you want a hyperlink inside the textbox, I'm afraid I can't help you with that portion of your problem without a little more research myself. But this much info should get you closer.

Code:
  txtYourTextBoxName.Value = <return value of Common dialog>
IF you use the Windows API to get at the Common Dialog, you'll find it exposed through a function, so the above becomes something like:
Code:
  txtYourTextBoxName.Value = GetCommonDialogReturn(<params>)
*Something like* are key words there; that's just pseudocode. I don't have the parameters memorised, I'm afraid. And I don't recall the actual name of the function as exposed by the API. So I used GetCommonDialogReturn to represent whatever the name should be. (Of course, when you declare the API function in your code, you can alias it with any legal name you like; you'll see what I mean if you use the code and read the Help File on &quot;Declare&quot; in VBA.)

Good luck!
-- C Vigil =)
(Before becoming a member, I also signed on several posts as
&quot;JustPassingThru&quot; and &quot;QuickieBoy&quot; -- as in &quot;Giving Quick Answers&quot;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top