wdDialogFileOpen question

D

Dave Yeager

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
 
J

Jay Freedman

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.
 
D

David Yeager

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.
http://www.mvps.org/word/FAQs/MacrosVBA/WordBasicCommands.
htm. The
 

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