[AccessD] Need help with return in a function

Kaup, Chester Chester_Kaup at kindermorgan.com
Thu Apr 28 13:53:08 CDT 2016


Thanks everyone for your assistance. I still have so much to learn.

-----Original Message-----
From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Heenan, Lambert
Sent: Thursday, April 28, 2016 1:44 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Need help with return in a function

John,

As rewritten by yourself (that 'return' line), the function returns False if the deletion was successful, so your example usage would be...

if Delete_File(somefile) = TRUE then
     Msgbox "Deleted Failed"
     do something
else
     Msgbox "Success"
end if

Lambert

-----Original Message-----
From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of John Bodin
Sent: Thursday, April 28, 2016 2:38 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Need help with return in a function

Hi Chester,

If a file doesn't exist (which you hope is the case after the Delete/Kill issued, Dir will return a 0 for "Len()" function.  If file doesn't get deleted for whatever reason, a number > 0 will be returned.

I think you can change the line to:

Delete_File = Len(Dir$(aFile)) > 0

In the code that calls Delete_File, you could have something like:

if Delete_File(somefile) = false then
     Msgbox "Deleted Failed"
     do something
else
     Msgbox "Success"
end if

John

John Bodin
sBOR Office Systems
jbodin at sbor.com


________________________________________
From: AccessD <accessd-bounces at databaseadvisors.com> on behalf of Kaup, Chester <Chester_Kaup at kindermorgan.com>
Sent: Thursday, April 28, 2016 1:55 PM
To: Access Developers discussion and problem solving
Subject: [AccessD] Need help with return in a function

Came across a bit of code in a database and I don't understand what one line is supposed to do or how it is intended to work. I get a syntax error of "Expected end of statement"  The line in question is return Len(Dir$(aFile)) >0. Thanks for the assistance.

Here is the whole function

Function Delete_File(aFile)
    Dim B As String
    On Error Resume
    Kill aFile
    On Error GoTo 0
    return Len(Dir$(aFile)) > 0         ' Make sure it actually got deleted.
End Function
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list