Test if a db is opened in a \Temp\ folder

ghudson

Registered User.
Local time
Today, 15:35
Joined
Jun 8, 2002
Messages
6,194
What is the best way to determine if the opened database is located in a users \Temp\ folder? I used to be able to test if a db was located @ C:\Windows\Temp\ or C:\WinNT\Temp\ Now with the various places Windows XP might open a db that was attached in an email, I am having a hard time figuring out the best way to test where the opened db is located. Is there anyway that I can easily code and test if a db is located in a \Temp\ folder no matter what the prefix location or drive before the \Temp\ folder is? Examples:

C:\Temp\Test.mdb
C:\Windows\Temp\Test.mdb
C:\WinNT\Temp\Test.mdb
C:\Documents and Settings\ghudson\Local Settings\Temp\Test.mdb

I need to test if True or False that the opened db is located in a \Temp\ folder.

Thanks!
 
Dim strMyDb as String

...

strMyDb = CurrentDB.Name

This should give you the fully qualified specification of the open database, including the device and path.

You should be able to use the InStr function from there to determine whether the name includes "/Temp/" as a substring. Be sure to use the type of comparison that is case insensitive. (I think it is vbTextCompare.)
 
Thanks for responding The_Doc_Man. Here is what I am using based on your suggestion...

Dim sDb As String, x As Variant
sDb = CurrentDb.Name
x = InStr(1, sDb, "\Temp", vbTextCompare)
If x = 0 Then
MsgBox "False"
Else
MsgBox "True"
End If

It is working but is this the best and cleanest way to get my results?
Is it possible that I could ever get a false "positive" (non 0)?

Thanks!
 

Users who are viewing this thread

Back
Top Bottom