By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,469 Members | 1,259 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,469 IT Pros & Developers. It's quick & easy.

Non-programmer needs help with VB code to locate file on hard drive

P: n/a
Long story short: My Access developer is letting me down. He doesn't
really know VB and he can't figure out how to do what I need.

Situation:
Access database that will be used locally on individual user's
machines.

What I need:
I need code to make Access look for a "security" file located on the
user's hard drive. If it finds the file, it allows the user to continue
into the application. If it doesn't find the file, the database shuts
down and does not let the user proceed.

I'm begging and pleading for help from all of you experts. I am not a
VB programmer, and I'm not so ignorant as to think I could teach myself
how to do this in the short time I have before I need to release this.

Is anyone willing to help me with this?

Nov 13 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a

"Wilsoch" <wi*****@comcast.net> schreef in bericht news:11**********************@f14g2000cwb.googlegr oups.com...
Long story short: My Access developer is letting me down. He doesn't
really know VB and he can't figure out how to do what I need.

Situation:
Access database that will be used locally on individual user's
machines.

What I need:
I need code to make Access look for a "security" file located on the
user's hard drive. If it finds the file, it allows the user to continue
into the application. If it doesn't find the file, the database shuts
down and does not let the user proceed.

I'm begging and pleading for help from all of you experts. I am not a
VB programmer, and I'm not so ignorant as to think I could teach myself
how to do this in the short time I have before I need to release this.

Is anyone willing to help me with this?


I guess something like the following will do what you want:

If Len(Dir("path to secure file")) > 0 then
let user in
else
Docmd.Quit
end if

Arno R
Nov 13 '05 #2

P: n/a
Searching the whole hard drive could take quite a long time. If you
know where the file should be (full path), checking for its existence
would be almost instantaneous.
If we must search there are several ways to do so, including recursive
calls to Dir() [not so efficient], the File System Object, The Shell
etc. If you tell us the least versions of Access and of Windows within
which this code must run then we may be able to suggest the most
efficient way that will work there.

I'm assuming you have a good reason to have a relationship with this
particuar Access Developer (works for free? is your spouse? only one
available on desert is? and or something such?).

Nothing I have said should be construed to indicate that I think your
method of protecting your work is likely to be effective.

Nov 13 '05 #3

P: n/a
Yes, I realize this isn't the greatest way of doing this. I'm open to
other suggestions. The only pre-requisite is that the database will be
located on the user's hard drive (it won't be posted to a shared server,
etc.).

And yes, there's a "relationship" with the developer in that I was
basically forced to use him.

The lowest versions should be as follows:
Windows 2000 and Access 2000

Those should be few and far between, though, and I would have no problem
requiring users to upgrade to Access 2003.

And yes, I have the full path to the file; it won't have to search the
whole hard drive.

Thank you for your response.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #4

P: n/a
Wilsoch wrote:
Long story short: My Access developer is letting me down. He doesn't
really know VB and he can't figure out how to do what I need.

Situation:
Access database that will be used locally on individual user's
machines.

What I need:
I need code to make Access look for a "security" file located on the
user's hard drive. If it finds the file, it allows the user to continue
into the application. If it doesn't find the file, the database shuts
down and does not let the user proceed.

I'm begging and pleading for help from all of you experts. I am not a
VB programmer, and I'm not so ignorant as to think I could teach myself
how to do this in the short time I have before I need to release this.

Is anyone willing to help me with this?


Maybe you can find a decent Access programmer at a nearby Access User's
Group.

See:

http://www.granite.ab.ca/access/usergroups.htm

You can also try something like monster.com. I suspect that some
experts posting here are not fully employed so maybe they will email
you privately. Many years ago a developer who owned a software company
in Texas suggested that hiring students was, in his experience, not a
great idea in spite of the hourly savings so I won't mention trying a
local university.

James A. Fortune

apophasis uh-PAH-fuh-sis noun : the raising of an issue by claiming
not to mention it. -- www.m-w.com

Nov 13 '05 #5

P: n/a
Yes, I realize this isn't the greatest way of doing this. I'm open to
other suggestions. The only pre-requisite is that the database will be
located on the user's hard drive (it won't be posted to a shared
server,
etc.).
And yes, there's a "relationship" with the developer in that I was
basically forced to use him.
The lowest versions should be as follows:
Windows 2000 and Access 2000
Those should be few and far between, though, and I would have no
problem
requiring users to upgrade to Access 2003.
And yes, I have the full path to the file; it won't have to search the
whole hard drive.
Thank you for your response.

Nov 13 '05 #6

P: n/a
Under the condtions you describe this function should work:

Public Function DoesFileExist(ByVal FilePath As String) As Boolean
With WizHook
.Key = 51488399
DoesFileExist = .FileExists(FilePath)
End With
End Function

Please, understand that Wizhook is a hidden, undocumented object first
appearing in Access 2000; many developers will not use it because of
this. I have used it successfully a few million times on a few hundred
machines; this may or may not mean that it will be reliable into the
forseeable future.
Of coure the wrapping is unnecessary; only
With WizHook
.Key = 51488399
DoesFileExist = .FileExists(FilePath)
End With
is required.

Nov 13 '05 #7

P: n/a
I really do appreciate your assistance. You cannot possibly know how
much.

Should I see if my developer can figure out where to put this code
(doubtful) or is it easy enough for me to stick it in?

I'd like to e-mail you an offering of thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #8

P: n/a
Upon reading the whole thread I think Arno's solution is superior to
mine.

Nov 13 '05 #9

P: n/a
"Arno R" <ar***********@tiscali.nl> wrote

I guess something like the following will do what you want:

If Len(Dir("path to secure file")) > 0 then
let user in
else
Docmd.Quit
end if

Put Arno R's code as first thing in the Open Event for the Form you specify
to be automatically Opened... that is set in the Tools | Startup item on the
menu, and you should have what you need.

I would comment than an Access developer who is not very familiar with VBA
is, indeed, NOT an "Access Developer" but just another Access User. Even
most "power users" with whom I am familiar know enough VBA to accomplish
this task and would, at the very least, be searching newsgroups on their own
to get the answer.

I see nothing wrong with Lyle's solution, and can vouch that he "knows his
stuff" when it comes to Access, but I also agree that Arno R's solution is
somewhat simpler and only uses documented features. Unless there is code you
need to run on the "let the user in" case, you could reduce that to a single
If... Then... with no Else. If your Developer can't figure out how to modify
the code, post back here after you dismiss him/her.

Larry Linson
Microsoft Access MVP
Nov 13 '05 #10

P: n/a
I could not agree with you more about the developer. I'm actually
married to an incredible developer (not Access), and working like this
is making me crazy. I've had no choice but to use this developer, as it
was a "directive" from my boss' boss, but I can tell you this: I'm not
happy about it.

Thank you all very much for your help. It's most appreciated.

Nov 13 '05 #11

P: n/a
Well the answer is using Access but try some VB script. Here is some
code you or your programmer should be able to modify if need be. If you
need to open Access Database, create module, copy, paste, these
procedures. You may change the path variable and file type. If you
don't won't to see msgbox prompts, please put a Debug.Print and open
the immediate window and you view the results, without interuption.
There is quite of bit of documentation in help files in Access VBA help
file. Good luck!

loringdo
Option Compare Database
Option Explicit

Sub FileSearchCount()

Dim i As Integer

With Application.FileSearch
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
Sub SearchSubFolders()

With Application.FileSearch
.NewSearch
.LookIn = "C:\My Documents"
.SearchSubFolders = True
.filename = "Run"
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
End With
End Sub

Sub SearchSubFoldersFileType()
Dim i As Integer
Dim fs
'msoFileTypeOfficeFiles
'msoFileTypeAllFiles

Set fs = Application.FileSearch

With fs
.LookIn = "C:\My Documents"
.FileType = msoFileTypeBinders
If .Execute > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" Binder file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no Binder files found."
End If
End With
End Sub
Sub FoundFilesCount()
Dim i As Integer

With Application.FileSearch
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
End With
End Sub
Sub FileSearchFolderCount()

Dim fs
Dim i As Integer
Set fs = Application.FileSearch
With fs
.LookIn = "C:\DPG\Reports\122"
.filename = "*.snp"
If .Execute > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub

Sub FileLastModifiedYeasterday()
Dim fs
Set fs = Application.FileSearch
With fs
.LookIn = "C:\My Documents"
.SearchSubFolders = True
.LastModified = msoLastModifiedYesterday
End With
End Sub

Nov 13 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.