Formula not working in query. (1 Viewer)

EdFred

knows enough, dangerous
Local time
Today, 10:55
Joined
Mar 2, 2007
Messages
129
So, I did a search on here and found what *should* work but does not.

First - the code

Code:
Public Function GetCustID() As String
        
strCustWebID = ""
                
        If CurrentProject.AllForms("Customer History Form").IsLoaded Then
            strCustWebID = [Forms]![Customer History Form]![Customer ID]
        Else
        
            If CurrentProject.AllForms("Invoice").IsLoaded Then
                    strCustWebID = [Forms]![Invoice]![Customer ID]
            End If
        End If
        
End Function
strCustWebID is a public string, so it sticks around after the function is done, also why I run the = "" at the beginning.

If step through the code and ?strCustWebID in the debug screen it returns what it should.

If I ?GetCustID in debug it returns nothing.
If I ?GetCustID and then ?strCustWebID the appropriate value is returned so the function seems to be working.

But of course when I place GetCustID() in the criteria of the query (because I can't put a string in the criteria) I get an empty query.

Other functions return appropriate values in the debug screen and queries, so it just seems to be this function.

I know it has to be something that I am just overlooking - but I'm apparently blind.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 07:55
Joined
Aug 30, 2003
Messages
36,137
You never set the return value:

GetCustID = strCustWebID
 

EdFred

knows enough, dangerous
Local time
Today, 10:55
Joined
Mar 2, 2007
Messages
129
You never set the return value:

GetCustID = strCustWebID

See I knew I was overlooking something exceedingly simple.

Now if you will excuse me, I have to go slam my head against a desk until it's a mushy pulp.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 07:55
Joined
Aug 30, 2003
Messages
36,137
I can tell you from experience that's not going to help. :p
 

Users who are viewing this thread

Top Bottom