bcbuchanan
asked on
Using a for next loop to assemble a search string from split array
Hi all -- I'm new (back) to EE and need some help. I have a textbox on a form (TxtAttribute1) and I want to pull the string out of it and then do a split based on ;. That part seems to be fine. However, I have a search string (strWhere) to which I want to add each member of the array, along with the appropriate filtering language for each individual member. There are other boxes that add similar filtering language to strWhere (date ranges, attributes, etc) but which aren't lited here. The code below doesn't cause any errors but it only returns the first member of the array (nothing else). I've tried everything I can think of with the loop and am at wit's end. so this is max points. I'm sure it's something small, so help me out, y'all....!
Dim strWhere As String
strWhere = "1=1"
Dim i As Integer
Dim sparts() As String
If Nz(Me.TxtAttribute1) <> "" Then
sparts = Split(Me.TxtAttribute1, ";")
For i = LBound(sparts) To UBound(sparts)
strWhere = strWhere & " AND " & "BaseDataTableItemA.TxtAtt ribute1 Like '*" & sparts(i) & "*'"
Exit For
Next i
End If
Dim strWhere As String
strWhere = "1=1"
Dim i As Integer
Dim sparts() As String
If Nz(Me.TxtAttribute1) <> "" Then
sparts = Split(Me.TxtAttribute1, ";")
For i = LBound(sparts) To UBound(sparts)
strWhere = strWhere & " AND " & "BaseDataTableItemA.TxtAtt
Exit For
Next i
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<It pulled the correct values from the array (huge) but unfortunately I need it formatted like the string in the attached image> Why?
what are the values in
BaseDataTableItemA.TxtAttr ibute1?
and the values from Me.TxtAttribute1?
what are the values in
BaseDataTableItemA.TxtAttr
and the values from Me.TxtAttribute1?
ASKER
strWhere is used to filter records in a subform that only displays after the search button is clicked. The subform's recordsource is BaseDataTableItemA, so whatever string criteria you enter in Me.TxtAttribute1 go to filter the records in the same named column in BaseDataTableItemA. I tried the code you provided and while it did get the array right, the filter didn't know what to do with the ( ) or lack of a second string.
better upload a copy of the db
ASKER
OK - here it is.
ComplaintsTest.mdb
ComplaintsTest.mdb
bcbuchanan,
do you know that the table that you have is not normalized?
what is the purpose of this table?
when you have repeating field, like what you have in your table, you need to break them out into separate tables..
have a read on this link
Description of the database normalization basics
http://support.microsoft.com/?kbid=283878
see also this demo about creating a third table to break a many to many relationship between two tables
http://office.microsoft.com/en-us/access-help/demo-set-the-relationship-between-two-tables-HA010254901.aspx?pid=CH100739911033
there are also lots of information on that link regarding table normalization
do you know that the table that you have is not normalized?
what is the purpose of this table?
when you have repeating field, like what you have in your table, you need to break them out into separate tables..
have a read on this link
Description of the database normalization basics
http://support.microsoft.com/?kbid=283878
see also this demo about creating a third table to break a many to many relationship between two tables
http://office.microsoft.com/en-us/access-help/demo-set-the-relationship-between-two-tables-HA010254901.aspx?pid=CH100739911033
there are also lots of information on that link regarding table normalization
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The solution is considered partial b/c capricorn1 provided the basis for the solution but with some different syntax. I made a couple of modifications to the syntax and the solution worked.
ASKER
output.png