Function return value

  • Thread starter Thread starter Tammy
  • Start date Start date
T

Tammy

Yet another question! I have created a function to
determine the correct path of a file (being opened from
an Access database). As there are multiple files where
the doc could be, I am trying to assign a value to the
funciton which indicates the correct location. I am
wondering how I can test the value of the function
without rerunning it every time. Here is the code I have
skethced out:

if (Records.DetPath(file)) = "error" then
goto errorline:
else
if (Records.DetPath(file)) = "w" then
strPath = "Work/"
else
strPath = "Save/"
endif
endif

I have the function in a module named "Records". Thanks
for any suggestions! I have tried looking
under "functions" on the Knowledge Base, but I'm not sure
exactly what to search for?!
 
Tammy said:
Yet another question! I have created a function to
determine the correct path of a file (being opened from
an Access database). As there are multiple files where
the doc could be, I am trying to assign a value to the
funciton which indicates the correct location. I am
wondering how I can test the value of the function
without rerunning it every time. Here is the code I have
skethced out:

if (Records.DetPath(file)) = "error" then
goto errorline:
else
if (Records.DetPath(file)) = "w" then
strPath = "Work/"
else
strPath = "Save/"
endif
endif

I have the function in a module named "Records". Thanks
for any suggestions! I have tried looking
under "functions" on the Knowledge Base, but I'm not sure
exactly what to search for?!

There are a couple of ways to do this. You could just capture the
function's return value in a variable, and then test that variable in
your "if" logic structure. In this case, though, you might be well
served to use a Select Case statement instead:

Select Case DetPath(file)
Case "error"
goto errorline:
Case "w"
strPath = "Work/"
Case Else
strPath = "Save/"
End Select

I took out the module-name qualifier because in all probability you
don't need it. You would only need it if you had the same procedure
name defined in multiple modules.

I don't really recommend the use of the GoTo statement in the way you're
using it, but that's your choice.
 
Back
Top