Code to find temp folder

J

JimP

I'm using the following code developed by Dev Ashish, to locate the temp
folder on a users pc. The "String$" function is causing an error on soime
users machines (perhaps because they are using MS-Access 97 or an older
runtime version or don't have a correct reference - not sure why).

Can you provide an alternate code sample, or resolution to the error?

Function fReturnTempDir()
'Returns Temp Folder Name
Dim strTempDir As String
Dim lngx As Long
strTempDir = String$(MAX_PATH, 0)
lngx = apiGetTempDir(MAX_PATH, strTempDir)
If lngx <> 0 Then
fReturnTempDir = Left$(strTempDir, lngx)
Else
fReturnTempDir = ""
End If
End Function
 
D

Douglas J. Steele

String$ works in Access 97, so the problem must be something else, likely an
issue with the References collection.

On the machine(s) where it's not working, open any code module, then select
Tools | References from the menu bar. Examine all of the selected
references.

If any of the selected references have "MISSING:" in front of them, unselect
them, and back out of the dialog. If you really need the reference(s) you
just unselected (you can tell by doing a Compile All Modules), go back in
and reselect them.

If none have "MISSING:", select an additional reference at random, back out
of the dialog, then go back in and unselect the reference you just added. If
that doesn't solve the problem, try to unselect as many of the selected
references as you can (Access may not let you unselect them all), back out
of the dialog, then go back in and reselect the references you just
unselected.

(NOTE: write down what the references are before you delete them, because
they'll be in a different order when you go back in)
 
T

Tom van Stiphout

On Tue, 6 May 2008 07:57:49 -0500, "JimP"

I don't know when the String function was first introduced. You may
want to find that out first before rewriting it. To me it sounds more
like a References problem and String just happens to be the first
function such users are exercising. See here for more info:
http://www.mvps.org/access/bugs/bugs0001.htm
and bookmark that site!

If you want to write your own, know that what this function does is to
fill a string with the given value for a given length.
Dim MyString
MyString = String(5, "*") ' Returns "*****".
MyString = String(5, 42) ' Returns "*****".

Armed with this information and with functions like Chr$() and Mid$()
you should be able to write your own version.

-Tom.
 
J

JimP

Thanks for the replies. This may be as simple as substituting "String" for
"String$". Perhaps "String$" is an issue to some installations for whatever
reason.
 
T

Tom van Stiphout

On Tue, 6 May 2008 10:27:30 -0500, "JimP"

That's not likely to work. String() returns a variant, whereas
String$() returns a string. That's the only difference.

If you had said: I'll use VBA.String, then you would have shown you
had read and understood my link, and agreed it was likely a references
issue.

-Tom.
 
B

Brendan Reynolds

JimP said:
I'm using the following code developed by Dev Ashish, to locate the temp
folder on a users pc. The "String$" function is causing an error on soime
users machines (perhaps because they are using MS-Access 97 or an older
runtime version or don't have a correct reference - not sure why).

Can you provide an alternate code sample, or resolution to the error?

Function fReturnTempDir()
'Returns Temp Folder Name
Dim strTempDir As String
Dim lngx As Long
strTempDir = String$(MAX_PATH, 0)
lngx = apiGetTempDir(MAX_PATH, strTempDir)
If lngx <> 0 Then
fReturnTempDir = Left$(strTempDir, lngx)
Else
fReturnTempDir = ""
End If
End Function


The String$() function actually pre-dates any version of Access, VB, or
Windows, it's an old BASIC function. So this is definitely a references
issue.
 
Top