Create criteria in a function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In a query i have the following in a criteria box.

strnames()

The function should be something like this (although of course this doesn't
work)

Function strNames()

strNames = <>Don and <>Bob

End Function

I've tried quotes in every combination I can think of but it still doesn't
work. Is it impossible to create a criteria in a function.

I was able to get the following to work when I put <> in front of strNames
in the criteria section of the query but it only allows me one name.

Function strNames()

strNames = "Don"

End Function

I need multiple names returned by the function to act as criteria in the
query. Any help would be greatly appreciated.
 
For multiple <> on the same field the Where clause needs to look like this

WHERE (((table.[table id])<>454 And (table.[table id])<>455))

yours looks like

WHERE (((table.[table id])<>454 And <>455))

The criteria box does this conversion for you during design but not at
runtime. Your best choice that i know is. Create a function with your whole
sql string and use it as your record source. You may copy and paste from your
current query sql. Then edit your where clause with a function like you have
as needed. I doubt this is clear so read this.

http://www.fontstuff.com/access/acctut17.htm

HTH
Martin
 
Back
Top