Hi Bob,
As Larry indicates, it would be very rare, indeed, to find a PC that does
not have a C: drive. On the other hand, I would expect that it is more common
to find a system that does not already have a Temp folder created, child to
the root drive (ie. C:\temp). You can trap for this error, and use VBA code
to create the temp folder if it is missing.
Here is code that I use in a startup form of one of my databases, to ensure
that the user is not attempting to run it from a file server. Instead, I want
them to only run it from their local hard drive:
Option Compare Database
Option Explicit
Private Sub Form_Load()
On Error GoTo ProcError
Dim strDriveType As String
' Ensure that the user is running this application from their own local hard
drive
strDriveType = DriveType(Left$(CurrentProject.FullName, 1))
If strDriveType <> "Hard Disk" Then
MsgBox "Please copy this application to a folder on your" & vbCrLf _
& "local hard drive before attempting to run it.", vbCritical, _
"Cannot Run From This Location..."
DoCmd.Quit
End If
' Populate global variable gstrUserName with user's NT Login ID
fOSUserName
' Set Explorer option to the value last selected by user
Me.fraOpenExplorer.Value = Nz(DLookup("blnOpenExplorer", "tblDefault"), 0)
ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Form_Load..."
Resume ExitProc
End Sub
The above procedure call the DriveType function, which I have in a
stand-alone module. This function is a slight adaptation from a KB article.
As you can see, it includes a constant for DRIVE_ROOT_NOT_EXIST.
Module Name: basDetermineDriveType
Option Compare Database
Option Explicit
' How To Determine the Type of Drive Using Win32 (Modified version)
'
http://support.microsoft.com/?id=161300
Private Declare Function GetDriveType Lib "kernel32" Alias _
"GetDriveTypeA" (ByVal sDrive As String) As Long
Function DriveType(sDrive As String) As String
Dim sDriveName As String
Const DRIVE_TYPE_UNDETERMINED = 0
Const DRIVE_ROOT_NOT_EXIST = 1
Const DRIVE_REMOVABLE = 2
Const DRIVE_FIXED = 3 '<---This is the only type we want to
allow.
Const DRIVE_REMOTE = 4
Const DRIVE_CDROM = 5
Const DRIVE_RAMDISK = 6
sDriveName = GetDriveType(sDrive & ":\")
Select Case sDriveName
Case DRIVE_TYPE_UNDETERMINED
DriveType = "has not been recognized"
Case DRIVE_ROOT_NOT_EXIST
DriveType = "Specified drive doesn't exist"
Case DRIVE_CDROM
DriveType = "CD-ROM drive."
Case DRIVE_FIXED
DriveType = "Hard Disk"
Case DRIVE_RAMDISK
DriveType = "is a RAM disk."
Case DRIVE_REMOTE
DriveType = "Network drive."
Case DRIVE_REMOVABLE
DriveType = "Removable Disk."
End Select
End Function
------------------------------------
Here is an abbreviated form of an error-handler in another procedure, where
I create an output folder if it is not already present. There are several
possible Err.Numbers that I test for, but error 76 is the important one in
this case:
ProcError:
Select Case Err.Number
Case 76 ' Path not found
MkDir CurrentProject.Path & "\" & conOutputFolder2
Resume
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in RearrangePFA procedure..."
End Select
Resume ExitProc
End Sub
In my case, the constant "conOutputFolder2" was defined at the beginning of
this procedure as follows:
Const conOutputFolder2 As String = "Processed PFA Files"
In your case, you could define a similar constant as:
Const conOutputFolder As String = "C:\temp"
(after you had first run code to ensure that the C drive was present). If
you defined it as above, then the make directory statement would be modified
as follows:
Select Case Err.Number
Case 76 ' Path not found
MkDir conOutputFolder
I have a download available where you can see all of this in action. It is
available on the Seattle Access web site.
http://www.seattleaccess.org/downloads.htm
Look for the following download:
Compilation of Tools by Tom Wickerath, October 2006 --
Download (656 kb) slides
Note: One of the Word documents in the downloadable zip file, "Find your
data.doc", was simply an announcement that I made at the start of my
presentation regarding the availability of a free article on a normally
subscription-only web service.
Hope this is helpful to you.
Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________