Advertisement

06.27.2008 at 08:05AM PDT, ID: 23521863
[x]
Attachment Details

revise function code searching pattern

Asked by fordraiders in Microsoft Access Database

access 2003 vba

What I have:

searching into a field for the 2 values from another table..

I have a code that uses a pattern...
sN = " " & rsNoun("fldFindMe1") & " " & rsNoun("fldFindMe2") & " "

and then I use the else statement for reverse....
sN = " " & rsNoun("fldFindMe2") & " " & rsNoun("fldFindMe1") & " "

Is there a way to reduce the code here....


Thanks
fordraiders


Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
Sub fndExceptions()
'Being called from vb.net 
' we are not replacing values...we are adding
' THIS ROUTINE WILL FIND THE EXACT PHRASE ONLY
 
Dim rsData As DAO.Recordset, rsNoun As DAO.Recordset
Set rsData = CurrentDb.OpenRecordset("tblData")
Set rsNoun = CurrentDb.OpenRecordset("tblExceptions")
Dim sD As String, sN As String, i, score
 
If rsData.RecordCount = 0 Then
    Exit Sub
End If
 
rsData.MoveFirst
Do Until rsData.EOF
    sD = " " & rsData("fldDescription") & " " ' added 09/04/2007
    rsNoun.MoveFirst
 
    Do Until rsNoun.EOF
        sN = " " & rsNoun("fldFindMe1") & " " & rsNoun("fldFindMe2") & " "  ' EXACT PHRASE ONLY added 06/14/2008
          
        If InStr(sD, sN) > 0 Then '< fldLightingQuery found in fldDescription
           'check if the match is a whole word
                  If InStr(sD, sN) Then ' DID HAVE Len(Sn)
                   rsData.Edit
                   rsData!fldAcronym2 = rsNoun("fldXrefType").Value
                   rsData!fldDescription = sD & " " & rsNoun("fldNewAdd").Value & " "
                   'rsData!fldDelete = "Y"
                   rsData.Update
                  End If
       Else
         
         sN = " " & rsNoun("fldFindMe2") & " " & rsNoun("fldFindMe1") & " "   ' REVERSE EXACT PHRASE ONLY added 06/14/2008
          
        If InStr(sD, sN) > 0 Then 
           'check if the match is a whole word
                  If InStr(sD, sN) Then ' DID HAVE Len(Sn)
                   rsData.Edit
                   rsData!fldAcronym2 = rsNoun("fldXrefType").Value
                   rsData!fldDescription = sD & " " & rsNoun("fldNewAdd").Value & " "
                   'rsData!fldDelete = "Y"
                   rsData.Update
                  End If
       End If
       End If
         
         rsNoun.MoveNext
    Loop
    rsData.MoveNext
Loop
rsNoun.Close
rsData.Close
Set rsNoun = Nothing
Set rsData = Nothing
 
End Sub
 
 
[+][-]06.27.2008 at 09:02AM PDT, ID: 21885128

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.27.2008 at 09:09AM PDT, ID: 21885191

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Access Database
Sign Up Now!
Solution Provided By: Chrisedebo
Participating Experts: 2
Solution Grade: A
 
 
[+][-]06.27.2008 at 09:45AM PDT, ID: 21885570

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906