Can't call custom functions created in Access

  • Thread starter Thread starter sabrown
  • Start date Start date
S

sabrown

I have created a custom function in Access as a Public Function and
saved it. Yet when I try to use the function Access refuses to
recognize it.

Option Compare Database

Public Function SUGGMDL(Cost As Currency, EAU As Long, Optional COMCDE
As String)
If COMCDE = "9SA" And EAU >= 1000 Then
SUGGMDL = "BIN"
Else
If Cost >= 7.35 And EAU >= 1000 Then
SUGGMDL = "SMI"
Else
If Cost < 7.35 And EAU >= 1000 Then
SUGGMDL = "ARP"
Else
SUGGMDL = "DIS"
End If
End If
End If
End Function

Scott
 
Have you tried Debug.Print suggmdl() in the immediate window? Also you
may want to add SUGGMDL = "DING" at the top before doing the
Debug.Print. If you DO NOT explicity set the return value of a function
outside any If...Then's, then function will return nothing and appear to
not have been called. Adding the 'DING' will help to identify if the
problem is internal to the function.
 
Yes, no problems cropped up in the Immediate window. Added the "DING"
also. Can't use the function in anything, reports, or queries.

Thxs! Scott
 
Fixed it now. Simple stupid error. But thanks for the tips. It will
help in the future.

Scott
 
Then that suggests to me that the problem is probably with the
If...Thens. Also, understand that FUNCTIONS are designed to return
values as such they are typicall found in statements where a value is
being evaluated or actuall used as in...

if myFunction() = 1

Select Case myFunction()

Me.txtControl = myFunction()

DLookup("fieldname", "tableName", "txtName =" & myFunction)
 
Back
Top