Hey everybody! As a person relatively new to VBA
programming, this newsgroup has been tremendously
helpful. A thank you to everyone who takes the time out
of their day to answer questions!

That being said, here's another one:

I'm trying to build into a custom form a command box that
would allow the user to select a file from their
directories, then have that info including the full path
be filled in to the dialog box. Perhaps code will further
explain:

Private Sub btnBrowse_Click()
With Dialogs(wdDialogFileOpen)
.Display
frmDataSelect.txtSource = .Name
End With
End Sub

"frmDataSelect" would be the custom form and "txtSource"
the text box where the filename is returned. This code
only gives the filename without the path present. Is
there a way I can have the entire file path returned?

-Dave

Re: wdDialogFileOpen question by Jay

Jay
Wed Aug 13 20:53:39 CDT 2003

Hi, Dave,

See the FileNameInfo section in
http://www.mvps.org/word/FAQs/MacrosVBA/WordBasicCommands.htm. The code you
need is

frmDataSelect.txtSource = WordBasic.FileNameInfo$(.Name, 1)

BTW, if the procedure you showed is in the frmDataSelect form, you don't
have to include "frmDataSelect." in this line; txtSource alone will be
recognized as the name of a control in the current userform.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://www.mvps.org/word

Dave Yeager wrote:
> Hey everybody! As a person relatively new to VBA
> programming, this newsgroup has been tremendously
> helpful. A thank you to everyone who takes the time out
> of their day to answer questions!
>
> That being said, here's another one:
>
> I'm trying to build into a custom form a command box that
> would allow the user to select a file from their
> directories, then have that info including the full path
> be filled in to the dialog box. Perhaps code will further
> explain:
>
> Private Sub btnBrowse_Click()
> With Dialogs(wdDialogFileOpen)
> .Display
> frmDataSelect.txtSource = .Name
> End With
> End Sub
>
> "frmDataSelect" would be the custom form and "txtSource"
> the text box where the filename is returned. This code
> only gives the filename without the path present. Is
> there a way I can have the entire file path returned?
>
> -Dave



Re: wdDialogFileOpen question by David

David
Thu Aug 14 11:13:11 CDT 2003

Awesome!! Thanks very much for all of your help!

-Dave

>-----Original Message-----
>Hi, David,
>
>Immediately after the FROM part of the SELECT statement,
you're inserting
>the *name* of the control literally into the select
string, where what you
>need is the *value* of the control. You have the same
problem after the
>WHERE part. Fixing this involves some nasty work with
quotes and ampersands.
>
>To repeat what I said before, you can simplify by
omitting the name of the
>userform when referring to the controls. Try this
variation:
>
> ...SQLStatement:= _
> "SELECT fig_num, item_num, smr, niin, cage,
> part_number, lead_line_desc, act_qty FROM " & _
> txtSource & " WHERE ((fig_num = " & _
> txtFigNo & "))", _
> PasswordDocument:="", ...
>
>Further down in the statement, the
DataSource:=frmDataSelect.txtSource part
>is OK as is, although you could remove the userform name
and its dot.
>
>I'm not sure the double parentheses are necessary, but my
SQL is a bit
>rusty.
>
>--
>Regards,
>Jay Freedman
>Microsoft Word MVP FAQ: http://www.mvps.org/word
>
>David Yeager wrote:
>> Awesome! That is tremendously helpful, but now I've run
>> into another roadblock:
>>
>> Using that data gathered from the form (including the
full
>> path that I have now managed to obtain thanks to your
>> help), I'm trying to insert a DATABASE field. The code
>> I've got right now looks like this:
>>
>> Selection.Range.InsertDatabase Format:=16, Style:=31,
>> LinkToSource:=True, _
>> Connection:="Entire Spreadsheet",
SQLStatement:= _
>> "SELECT fig_num, item_num, smr, niin, cage,
>> part_number, lead_line_desc, act_qty FROM
>> frmDataSelect.txtSource WHERE ((fig_num =
>> frmDataSelect.txtFigNo))" _
>> & "", PasswordDocument:="",
PasswordTemplate:="",
>> WritePasswordDocument _
>> :="", WritePasswordTemplate:="",
>> DataSource:=frmDataSelect.txtSource _
>> , From:=-1, To:=-1, IncludeFields:=False
>>
>> The important stuff in all this gobbledeegook is the use
>> of frmDataSelect.txtSource and .txtFigNo... coding it
this
>> way does not work. I've also tried concatanation (using
>> &) to add the stuff and that doens't work either. Any
>> other ideas? Thanks!
>>
>> -Dave
>>
>>
>>> -----Original Message-----
>>> Hi, Dave,
>>>
>>> See the FileNameInfo section in
>>>
http://www.mvps.org/word/FAQs/MacrosVBA/WordBasicCommands.
htm. The
>>> code you need is
>>>
>>> frmDataSelect.txtSource =
WordBasic.FileNameInfo$(.Name, 1)
>>>
>>> BTW, if the procedure you showed is in the
frmDataSelect form, you
>>> don't have to include "frmDataSelect." in this line;
txtSource alone
>>> will be recognized as the name of a control in the
current userform.
>>>
>>> --
>>> Regards,
>>> Jay Freedman
>>> Microsoft Word MVP FAQ: http://www.mvps.org/word
>>>
>>> Dave Yeager wrote:
>>>> Hey everybody! As a person relatively new to VBA
>>>> programming, this newsgroup has been tremendously
>>>> helpful. A thank you to everyone who takes the time
out
>>>> of their day to answer questions!
>>>>
>>>> That being said, here's another one:
>>>>
>>>> I'm trying to build into a custom form a command box
that
>>>> would allow the user to select a file from their
>>>> directories, then have that info including the full
path
>>>> be filled in to the dialog box. Perhaps code will
further
>>>> explain:
>>>>
>>>> Private Sub btnBrowse_Click()
>>>> With Dialogs(wdDialogFileOpen)
>>>> .Display
>>>> frmDataSelect.txtSource = .Name
>>>> End With
>>>> End Sub
>>>>
>>>> "frmDataSelect" would be the custom form
and "txtSource"
>>>> the text box where the filename is returned. This
code
>>>> only gives the filename without the path present. Is
>>>> there a way I can have the entire file path returned?
>>>>
>>>> -Dave
>>>
>>>
>>> .
>
>
>.
>