Search in fields with allowed multiple Values

Vladko

New member
Local time
Yesterday, 17:58
Joined
Aug 8, 2016
Messages
2
Dear All.

Could you please resolve me this issue?
To simplify I have table with 4 fields.
  • IssueID
  • Model (Combo Box ; Table/Query ; Allow multiple values - Yes)
  • Region (Combo Box ; Table/Query ; Allow multiple values - Yes)
  • Remark

I have filled them with different data. For example:
in Region in first field: "UK", "US", "France". In second field: "UK", "France".
in Model in first field "A1", "A2", "A3". Ind second field "A2", "A3". I hope you get it :-)

Now i have two forms. One for data search and other which is displaying result. If I want to search in fields which don't have allowed multiple values then i use this code:
Private Sub but_Search_Click()
condi = "1=1"
If Len(Me.Issue_ID.Value) > 0 Then
condi = condi & " AND [Issue ID] = '" & Me.Issue_ID.Value & "'"
End If
DoCmd.OpenForm "FOR_TAB_CAMP", acNormal, , condi, acFormEdit, acWindowNormal
End Sub

But when I want to search in fields which have allowed multiple values in them, then this code don't work. How should I proceed? How can I find for example records which have in Model field value "A2"? Or in Region field value "France".
 
Multi-valued fields can be more hassle then they are worth. If you are creating a field that has values that you are likely to perform some task on e.g. search, join, then I would strongly advise creating another table to store the values (1 to many).

Nevertheless, you should be able to set a criteria like this:

[Model].value = 'A2'
 
If the data is separated by delimiters, then use the asterisk and LIKE.
Select * from table like [field] like "UK"

But this can give false results. This is why relational db demand a new record for EVERY item. You don't have to save space in order to get correct data.
 
I would recommend not using MV field(s) since they are unique to Access.
However, you may get more info from this M$oft link.
 
Thank you guys.

So how should I proceed if in one "IssueID" can occur in multiple "Region". If I want from users to input in one "IssueID" multiple "Region" is there any other way that except multiple values in one field?
 
The point is, if you avoid multivalued fields that many recommend, then you create a separate table. This is the traditional, and recommended approach for relational database.

You have Issues and Regions, and it seems in your situation
one "IssueID" multiple "Region"

Issue-->IssueInRegion<-----Region

consider:
tblIssue
IssueID PK
IssueName


Code:
IssueID   IssueName
1              bad water
2              fire hazard
3              poor health conditions
4              poor infrastructure
tblRegion
RegionId PK
RegionName

Code:
RegionId  RegionName
1 NorthWest
2 Central
3 SouthWest
4 Southest



tblIssueInRegion junction table

This identifies an issue in multiple regions.

IssueID compound PK
RegionID

Code:
IssueId    RegionId
1               2
1               3
2               2
3               1
3               4
 

Users who are viewing this thread

Back
Top Bottom