Loading path and file name into a text box

S

SAC

I'm using Ken Getz's standard Windows File Open/Save dialog box from The
Access Web.

There's a function in it called testit():

I want to return the name of the path and file to a textbox on the calling
form, but I can't figure out what part of the msgbox line to put into the
textbox.

Here's the function with the message box line:

Function TestIt()
Dim strFilter As String
Dim lngFlags As Long
strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)", _
"*.MDA;*.MDB")
strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF")
strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
MsgBox "You selected: " & ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Hello! Open Me!")
' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Debug.Print Hex(lngFlags)
End Function

What portion the msgbox line do I make the text box equal to?

Thanks.
 
D

Douglas J. Steele

The actual call to the function returns the information.

Add the following declaration to the beginning of TestIt:

Dim strFile As String

then change the MsgBox line to:

strFile = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Hello! Open Me!")
MsgBox "You selected: " & strFile

and you'll see that strFile will contain the path and filename.
 
S

SAC

Thanks!

How do I load this into my textbox? I guess I don't know how to handle the
return value of a function. I weould like it to end up in a textbox on my
form.

I'm calling the function with a command button on the form, so would I put
something like this in it:

txtTextBox = strFile?

Thanks
 
S

SAC

OK, I almost have it figured out.

In the on_click event of the command button I have

Testit(txtTextBox)

but it comes back and says Type Mismatch.

Is strFile the return value? If so, it's a string isn't it?

Thanks.
 
D

Douglas J. Steele

If you want Ken's TestIt function to pass back the filename to you, include
the changes I mentioned earlier, and add the following at the end:

TestIt = TrimNull(strFile)

Now, in the OnClick event of the command button, you need
txtTextBox =TestIt()

or, more correctly,
Me!txtTextBox.Value =TestIt()
 
S

SAC

I tried and it doesn't show up in the text box.

I added me.refresh and it still isn't there.

Any other ideas?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top