error in a report when returning a value from a function

  • Thread starter Thread starter mkoehler
  • Start date Start date
M

mkoehler

Guest
I have a text box in a report that calls a function. With the debug window open, I can see that what I am returning is correct, or I should say, the value that I want. However, the text box in the report only says "error" when I run it. If I look at "a" in the debug window it is exactly what I want. I just cant get it to return the value to the report without the "error".

code below

Function getsubprod()

Dim dbcurrent As Database
Dim rstproduct As Recordset
Dim a As String
Set dbcurrent = CurrentDb
Set rstproduct = dbcurrent.OpenRecordset("get_sub_prod")
a = ""

rstproduct.MoveFirst

Do Until rstproduct.EOF

If [rstproduct]![y] = [Reports]![qry_equipment_rpt1]![full_product] Then

a = a & rstproduct!x & " " & [rstproduct]![product] & Chr(13)

End If

rstproduct.MoveNext

Loop

Debug.Print a


If a <> "" Then
getsubprod = a
Else
getsubprod = " "

End If

End

Close

End Function
 
Is the function public? Otherwise when you run the report the function may be out of scope if the function is scoped to another form or module
 

Users who are viewing this thread

Back
Top Bottom