How do you Highlight a file name and copy the path and name to avariable using VBA?

J

JHB

Hi:

I understand there is a VBA command you can use to go to a particular
folder and display the files in the folder so that one can be
highlighted and selected by a button click AND the reference is such
that you can use that command with a = sign to store the file address
and name as a variable.

Can someone tell me what that command is and, if there is no such
command, how one can create a "Point and Click" process to store a
file path and name in a variable?

I need to use it as part of a restore process from a list of backed up
files.

Thanks in advance

John Baker
 
R

Rob Parker

I don't know of any VBA command that does what you want. That doesn't mean
there isn't one - but I suspect I'd know of it if there was.

There is VBA code that will do it. I regularly use code based on the API
which calls the standard Windows File Open/Save dialog, available from The
Access Web http://access.mvps.org/access/api/api0001.htm

HTH,

Rob
 
J

JHB

I don't know of any VBA command that does what you want.  That doesn't mean
there isn't one - but I suspect I'd know of it if there was.

There is VBA code that will do it.  I regularly use code based on the API
which calls the standard Windows File Open/Save dialog, available from The
Access Webhttp://access.mvps.org/access/api/api0001.htm

HTH,

Rob

Thank you. I think thats what I need -- appreciate your help!

John
 
J

JHB

I don't know of any VBA command that does what you want.  That doesn't mean
there isn't one - but I suspect I'd know of it if there was.

There is VBA code that will do it.  I regularly use code based on the API
which calls the standard Windows File Open/Save dialog, available from The
Access Webhttp://access.mvps.org/access/api/api0001.htm

HTH,

Rob

I have this working very well -- it offers the correct file list and
disdplayes the selected file path and name, however I cannot seem to
get it to pass the variable to another routine. It would be fine if it
was a global variable, but it doesnt seem to be.

I have set the following code to test the process (called from an
Access form):

Private Sub Form_Open(Cancel As Integer)
Call TestIt
MsgBox lngFlags
End Sub

MSGBOX should throw back the contents of the variable but all I get is
a blank.

Any idea what I am doing wrong?

Thanks



John
 
D

Douglas J Steele

You need to learn about scope of variables.

Because lngFlags is declared in the TestIt function, its scope is limited to
that function: it's unknown outside of that particular function. Solutions
to the problem would be to declare lngFlags as a public variable outside of
the function, change the function to accept passing a reference to lngFlags
so that its value would be passed back to the calling program, or have the
function return the value of lngFlags (it doesn't currently return any
value).

However, the fact that your code runs without error points out what to me is
a more serious problem. You have not told VBA to insist that all variables
be declared. If you did, then you'd get an error when you tried to run
Form_Open because it's referring to a variable that hasn't been declared.
Every module should contain the line Option Explicit at the top. To have VBA
automatically add that from now on, you can go into Tools | Options in the
VB Editor and ensure that Require Variable Declaration is checked on the
Editor tab. You'll have to go back and add that line to all existing modules
though.



"JHB" wrote in message

I don't know of any VBA command that does what you want. That doesn't
mean
there isn't one - but I suspect I'd know of it if there was.

There is VBA code that will do it. I regularly use code based on the API
which calls the standard Windows File Open/Save dialog, available from The
Access Webhttp://access.mvps.org/access/api/api0001.htm

HTH,

Rob

I have this working very well -- it offers the correct file list and
disdplayes the selected file path and name, however I cannot seem to
get it to pass the variable to another routine. It would be fine if it
was a global variable, but it doesnt seem to be.

I have set the following code to test the process (called from an
Access form):

Private Sub Form_Open(Cancel As Integer)
Call TestIt
MsgBox lngFlags
End Sub

MSGBOX should throw back the contents of the variable but all I get is
a blank.

Any idea what I am doing wrong?

Thanks



John
 

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