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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browse for file Issue

Status
Not open for further replies.

jedel

Programmer
Jan 11, 2003
430
AU
Hey all,

I'm having a problem with the below peice of code. You may be familiar with it as it originally came from this site.

Basically Its a BrowseForFile code that opens the browse for file dialogue where you can select a file and the database places the filepath and file name into a field.

What I wouldl ike to do is make thise code public. Here is the code so far...
Code:
Public Sub Openfile(strCap As String, strLoc As String, strFolder As String)
Dim strTemp As String 'For returning if user cancels
    Dim strNewPath 'The new path the user selects
    Dim strCaption As String ' What we want the box to say
        
    strCaption = ""
    If Not IsNull(strLoc) Then
        strTemp = strCap & strFolder
        
    Else
    strTemp = strCap & strFolder 'Me.lblPath1.Caption
    MsgBox "strTemp " & strCap & strFolder
    End If

   strCaption = strCap & strFolder
   strNewPath = BrowseForFile(strTemp, strCaption)

    'playsound (strNewPath)

If IsNull(strNewPath) Or strNewPath = "" Or strNewPath = "\" Then
   MsgBox "strTemp " & strTemp & "StrNewpath " & strNewPath, vbOKOnly
    strLoc = strNewPath
Else
    strLoc = strNewPath
        
End If
End Sub

The setting I use when I call the code are;
strCap = CurrentProject.path
strLoc = me.txtTemplateLoc (the call code is in the same form as this field)
strFolder = "\files\" The folder location of the file I wish to select.

Everything works fine right up to part where I want the filepath and name placed into the me.txtTemplateLoc field. From there it does nothing. Any help would be appreciated

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
I take it the Public Sub is in a module as opposed to the form.

I am not entirely sure of this, as I am getting to grips with this myself...

But you could try changing the Public Sub to Public Function.

The before the End Function line insert Openfile = strLoc

This should return the path string back to the form that originally called the function. Then on your form

me.txtTemplateLoc = OpenFile

Take it Easy
Man with one chopstick go hungry
 
Hi Jedel,

Try looking at this, bit longer code but it works fine for me.

thread702-1467575

Hope this helps.

Nim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top