Solved

FileLen in Access 2007

Posted on 2013-01-31
14
438 Views
Last Modified: 2013-03-22
Hello,

I have a simple program that I use FileLen to detemine if I found a file of a given name.  It all works nicely BUT, if I do not set Sandbox mode to 2 in the registry, it will not work at all.  I need to give this program to a user and I do not want to be editing registries on a regular basis.

I want a way to enable the FileLen function without changing the registry.  I am also open to a different command that can solve my issue.  I only need to know if it found the file or not.  Maybe IfExist if there is such a thing.

Thanks
0
Comment
Question by:vmccune
  • 5
  • 4
  • 4
  • +1
14 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
did you place your app in a trusted location?

office button > access options > trust center
 click on trust center settings  button
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
Have you tried the Dir() function?  The dir function accepts several arguments, the first being a filename.  If you pass it a full name, it will return the file name if the file actually exists in the folder you provided.  If not, it returns an empty string (may be null).

I'm not really sure what you mean by "need to know if it found the file or not"

Are you providing a path/file name and then searching for the file?
0
 

Author Comment

by:vmccune
Comment Utility
Trusted Location: Yes

The search looks for FileA,  if the FileLen(FileA) is > 0, it writes the value to a fileSize field and moves on.

If it does not find a number for FileLen(FileA), it looks for FileLen(FileA_1) then _2,_3 up to 5 to try and find the picture.  The pictures are set up by the art dept and for varous reasons, the initial name is not always there.

I also then can provide them a list of pictures I am missing and run some sales reports with pictures.

The code is fine and works without a problem as long as I set Sandbox mode to 2.  This seems to me like a crazy way to get access to this command.  There muct be a better way.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
I'm pretty sure ... this is not going to happen  - even with a Trusted Location set - unless you set Macro Security (aka Sandbox) to Low.  This can be done by the user via the Access UI - or directly in the Registry of course.

mx
0
 

Author Comment

by:vmccune
Comment Utility
It is set to lowest for macro but still will not work without also changeing in the registry.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
"without also changeing in the registry."
Changing in VIA the UI does change it in the Registry, since that is where the setting is stored.

What version of Access is this ?

mx
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
"BUT, if I do not set Sandbox mode to 2 in the registry, it will not work at all"

What does "it will not work at all" mean?  Are you getting an error message?  Is it just not returning a value for a valid filename?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:vmccune
Comment Utility
2007,

MX, it does not change that value in the registry.  That is why I am asking.

Not work at all.  Pops up with a dialog box that says FileLen as if looking for a value.  I change it in SB and it works fine.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
How about using the FileSystemObject:

Public Function fnFileLength(FileName as string) as long

    Dim fso as object, fsoFile as object
    set fso = createobject("scripting.filesystemobject")
    set fsoFile = fso.getfile(FileName)
    fnFileLength = fsofile.size

    set fsoFile = nothing
    set fso = nothing
End Function
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
"MX, it does not change that value in the registry.  That is why I am asking."

Well, as I recall now ... there are two different Registry settings.  Setting Macro Security via the UI definitely changes one of them.  

The setting that is changed by Macro Security is shown below ... you can confirm this yourself via the UI. (this is A2003)
1
0
 

Author Comment

by:vmccune
Comment Utility
This is the one I needed to change.  I have multiple versions of access so I changed in each.
registry.jpg
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
This might be useful and applies to A2007:

http://office.microsoft.com/en-us/access-help/use-sandbox-mode-in-access-2007-HA010167429.aspx

And this includes the above and is more comprehensive. I'm still trying to find the other key - that is referenced in these KBs - on my A2010 system.

http://office.microsoft.com/en-us/access/HA012301901033.aspx
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
"This is the one I needed to change"
Yes ...
Odd - that key (SandBox) does not show under Engines on my A2010 system here at work - or my A2003 system here at work either.

mx
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
Comment Utility
Why mess with the registry settings?

Did you try the FileSystemObject option?

I didn't put any error handling in that so, my guess is that it will raise an error if the file isn't found.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now