473,378 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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
11 1900

"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
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
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
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
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
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
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
Upon reading the whole thread I think Arno's solution is superior to
mine.

Nov 13 '05 #9
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Kartic | last post by:
Hello, I downloaded the Win32 installer for Twisted 1.3.0, Python 2.3. The installer, when executed under my login, fails as it requires administrator rights to install (why they have it as a...
1
by: Markus Ernst | last post by:
Hi I wrote a function that "normalizes" strings for use in URLs in a UTF-8 encoded content administration application. After having removed the accents from latin characters I try to remove all...
4
by: bwmiller16 | last post by:
Guys - I'm doing a database consistency check for a client and I find that they're building unique indexes for performance/query reasons where they could be using non-unique indexes. Note...
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
3
by: Ivan | last post by:
Hi, how to filter out non-digit chars when user writes text to System.Windows.Forms.TextBox? Thanks, Iavmn
13
by: Academic | last post by:
I have a MDI form, sometimes child forms and sometimes forms that are neither If I close the app the child forms closing and closed event happens followed by the Mdi form receiving the...
0
by: Wijnand Kroes | last post by:
Hi guys, I have a C#.NET client which sends SOAP requests to .Net webservices and non ..Net webservices. If I do not add a SOAP header a get a valid response from all webservices. If I do add...
7
by: siddhu | last post by:
Dear Experts, I have a question. I wrote the following code class A { public: void g(){}
6
by: Fabian Wein | last post by:
Hi, is there a way to call a const function from non const function? I have a non-const List GetList(); and want my
3
by: George2 | last post by:
Hello everyone, I am debugging MSDN code from, http://msdn2.microsoft.com/en-us/library/0eestyah(VS.80).aspx here is my output, 1>main.cpp
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.