Solved

FileLen in Access 2007

Posted on 2013-01-31
14
469 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38840630
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)
ID: 38840633
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
ID: 38840694
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 75
ID: 38840905
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
ID: 38840984
It is set to lowest for macro but still will not work without also changeing in the registry.
0
 
LVL 75
ID: 38841035
"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)
ID: 38841081
"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
 

Author Comment

by:vmccune
ID: 38841141
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)
ID: 38841163
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
ID: 38841247
"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
ID: 38841324
This is the one I needed to change.  I have multiple versions of access so I changed in each.
registry.jpg
0
 
LVL 75
ID: 38841342
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
ID: 38841357
"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
ID: 38841384
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

777 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