"SEAN DI''''ANNO" <(E-Mail Removed)> wrote in
message news

F4D4AC5-45EE-4EB8-9E09-(E-Mail Removed)
> Good morning,
>
> can come one please help me with my following datasbase dilemma
>
> The user will be asked, "What Catalogue Code do you require ?" The
> question will be repeated until there are no more catralogue codes.
> I would like to build up a STR statement in the background.
>
> Suppose the user enters 2 Catalogue Codes;
>
> E.G Item 1, Item 2. I would like a variable to buld up a resulting
> STR statement of
>
> code]InStr([CatalogCode],"Item1")+InStr([CatalogCode],"Item2")[/code].
>
> I then want the database to automatically build a query with the STR
> statement so that it can be used again. The reason being.........The
> database will be used to track different promotions and therefore
> have a different STR statment for each promotion.
>
> As always, If you could give me the basic skeleton code, if its
> possible?, I would really appreciate it.
>
> Thank you.
I'm not sure exactly what you're trying to do, so I'm not sure which of
several possible approaches to the problem is best for you.
One way is to build the WHERE clause of a SQL select statement, like
this:
Dim strWhere As String
Dim strCode As String
Dim strSQL As String
Do
strCode = InputBox("What Catalogue Code do you require ?")
If Len(strCode) > 0 Then
strWhere = strWhere & _
" OR CatalogCode='" & strCode & "'"
End If
Loop Until Len(strCode) = 0
If Len(strWhere) > 0 Then
MsgBox _
"You didn't enter any catalogue codes!", _
vbExclamation
' maybe exit from here?
Else
strWhere = Mid$(strWhere, 5)
strSQL = _
"SELECT * FROM YourTable WHERE " & strWhere
' ... do something with this SQL ...
End If
Another, less efficient (but handy) way to do it is to build a delimited
list of the codes you want to search for, and then use a single InStr
function to see if a record is in that list:
Dim strList As String
Dim strCode As String
Dim strSQL As String
Do
strCode = InputBox("What Catalogue Code do you require ?")
If Len(strCode) > 0 Then
strList = strList & "," & strCode
End If
Loop Until Len(strCode) = 0
If Len(strList) > 0 Then
MsgBox _
"You didn't enter any catalogue codes!", _
vbExclamation
' maybe exit from here?
Else
strList = Chr(34) & strList & "," & Chr(34)
strSQL = _
"SELECT * FROM YourTable " & _
"WHERE InStr(" & strList & ", CatalogueCode) > 0"
' ... do something with this SQL ...
End If
Or, once you've built the list, you could apply the InStr function in
code to see if any given record meets the criteria.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)