Link to home
Start Free TrialLog in
Avatar of stuckp1
stuckp1

asked on

Access 2010 VBA and Regex: Unable to iterate through MatchCollection. Match generates "data member not found" error.

Hi,
The Goal:
I'm trying to use regular expressions to find repeating patterns in a string.
The string is "__CarrierCode__RZP__LocationCode__DQ1__Server1Nr__"
I want to thus find
"__CarrierCode__" , "__LocationCode__" and "__Server1Nr__"
The pattern is (__\w+?__)+

The code I'm using:
    Dim searchStr As String
    searchStr = "__CarrierCode__RZP__LocationCode__DQ1__Server1Nr__"
    Dim regExp As Object
    Set regExp = CreateObject("vbscript.regexp")
    Dim colregmatch As MatchCollection
    With regExp
        .Pattern = "(__\w+?__)+"
        .IgnoreCase = True
        .Global = True
        .Multiline = True
    End With
    
    
    Set colregmatch = regExp.Execute(searchStr)
    Dim match As match
    
    
    For Each match In colregmatch
        Debug.Print match.Groups(1).Value
    Next

Open in new window


The Problem
The type Match is known by Intellisense, but not by the compiler.
I get a "data member not found" for match.Groups(1).Value.

User generated image
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stuckp1
stuckp1

ASKER

I see Groups() method call has been replaced in your code by submatches(). This helps!
Thank you!
Peter
Glad to help!