Application Object Error 5017

Hi all, hope all is well.

Question: Got two button on a form to validate the data entered. The first button works like a charm. Why do i get an Error 5017: Application-defined or object-defined error? on the second button (command8)

Private Sub Command6_Click()
Dim regularexpressionobject As Object
Set regularexpressionobject = New VBScript_RegExp_10.RegExp

With regularexpressionobject
 .Pattern = "^(([a-zA-Z0-9\.\-_\&]+)([a-zA-Z0-9]+)@([a-zA-Z0-9\-]+)(\.[a-zA-Z0-9\-]+){1,6})$"
 .IgnoreCase = True
 .Global = True
End With

If regularexpressionobject.Test(EmailAddress.Value) Then
MsgBox "valid", vbOKOnly
Else
MsgBox "invalid", vbOKOnly
End If
End Sub

Private Sub Command8_Click()
Dim regularexpressionobject As Object
Set regularexpressionobject = New VBScript_RegExp_10.RegExp

With regularexpressionobject
 .Pattern = "(?i)\bbox\ |post|private|\bpo\ |\bpobox|\bbag\ |p\.o$"
 .IgnoreCase = True
 .Global = True
End With

If regularexpressionobject.Test(StreetAddress.Value) Then
MsgBox "valid", vbOKOnly
Else
MsgBox "invalid", vbOKOnly
End If
End Sub
 
Thanks
Sean
LVL 1
SeanNijAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim P.Commented:
I would check references.

Ctrl+G then Tools --> References. See if any are marked missing.
0
SeanNijAuthor Commented:
Nope nothing missing. Keep in mind - both buttons are on the same form. Press the first one and it works - press the second one and i get that error?
0
Rey Obrero (Capricorn1)Commented:
try releasing the object variable  { regularexpressionobject } after you use it

set regularexpressionobject=nothing
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

SeanNijAuthor Commented:
Nope no luck.

Could it be something to do with the pattern - may an incorrect pattern stuff it up?
0
Rey Obrero (Capricorn1)Commented:

try this

Private Sub Command6_Click()
Dim regularexpressionobject As Object
     'Set regularexpressionobject = New VBScript_RegExp_10.RegExp
Set regularexpressionobject = CreateObject("VBScript.RegExp")

With regularexpressionobject
 .Pattern = "^(([a-zA-Z0-9\.\-_\&]+)([a-zA-Z0-9]+)@([a-zA-Z0-9\-]+)(\.[a-zA-Z0-9\-]+){1,6})$"
 .IgnoreCase = True
 .Global = True
End With

If regularexpressionobject.Test(EmailAddress.Value) Then
MsgBox "valid", vbOKOnly
Else
MsgBox "invalid", vbOKOnly
End If
Set regularexpressionobject = Nothing

End Sub

Private Sub Command8_Click()
Dim regularexpressionobject As Object
         'Set regularexpressionobject = New VBScript_RegExp_10.RegExp
Set regularexpressionobject = CreateObject("VBScript.RegExp")

With regularexpressionobject
 .Pattern = "(?i)\bbox\ |post|private|\bpo\ |\bpobox|\bbag\ |p\.o$"
 .IgnoreCase = True
 .Global = True
End With

If regularexpressionobject.Test(StreetAddress.Value) Then
MsgBox "valid", vbOKOnly
Else
MsgBox "invalid", vbOKOnly
End If
Set regularexpressionobject = Nothing

End Sub
 

0
SeanNijAuthor Commented:
Exactly same error msg.
0
Rey Obrero (Capricorn1)Commented:
btw, which line is higlighted?
0
SeanNijAuthor Commented:
If regularexpressionobject.Test(StreetAddress.Value) Then

if i copy the pattern from the first button into the second set of code it works - can it be the pattern itself?
0
Rey Obrero (Capricorn1)Commented:
remove the .value

If regularexpressionobject.Test(StreetAddress) Then

how do you pass the StreetAddress?
0
Rey Obrero (Capricorn1)Commented:
SeanNij,
it is the pattern that is giving you the error.
0
Rey Obrero (Capricorn1)Commented:
try using this pattern

  .Pattern = "^([a-zA-Z0-9\.\-_\&])([a-zA-Z0-9]+)"


Private Sub Command8_Click()
Dim regularexpressionobject As Object
         'Set regularexpressionobject = New VBScript_RegExp_10.RegExp
Set regularexpressionobject = CreateObject("VBScript.RegExp")

With regularexpressionobject
' .Pattern = "(?i)\bbox\ |post|private|\bpo\ |\bpobox|\bbag\ |p\.o$"
 
 .Pattern = "^([a-zA-Z0-9\.\-_\&])([a-zA-Z0-9]+)"

 .IgnoreCase = True
 .Global = True
End With

If regularexpressionobject.Test(StreetAddress.Value) Then
MsgBox "valid", vbOKOnly
Else
MsgBox "invalid", vbOKOnly
End If
Set regularexpressionobject = Nothing

End Sub
 
0
SeanNijAuthor Commented:
then it works.

however not allowing / disallowing what i need - so therefor the pattern line is wrong.
0
Rey Obrero (Capricorn1)Commented:
SeanNij,
<so therefor the pattern line is wrong.>
wish i could see from the crystal ball what  pattern you need
i can not guess what you need to filter,
0
SeanNijAuthor Commented:
and here i thought you would be able too...;)

I want to check that address lines may contain the phrase PO BOX/PRIVATE BAG/POST or any abbreviation there off.

Question: Do you ever sleep?
0
Rey Obrero (Capricorn1)Commented:
I just woke up.

sean,
can you post some real data, of different variation.
0
SeanNijAuthor Commented:
CompanyName,StreetAddress,PostalAddress,City
Tarsus Networking (Pty) Ltd.,Prosperity Park Democracy Way Milnerton 7441,PO Box 19234,Vlaeberg
Bromor Foods (Pty) LTD,No 5 Sunrise Circle Ndabeni,PO Box 28,Cape Town
Trencor Ltd,PO Box 13160 Dowerglen Ext 7,1313 Main Tower, Heerengracht Street Standard Bank Centre, CT
USABCO,,PO Box 277,Bellville Boland Bank,333 Main Road Paarl",PO Box 4,Paarl
0
Rey Obrero (Capricorn1)Commented:

this

 .Pattern = "^([a-zA-Z0-9\.\-_\&amp;()])([a-zA-Z0-9]+)"

pass the the top three sample, the last one failed due to the  " in { Main Road  Paarl",PO Box 4,Paarl }  which i think is a wrong format

0
SeanNijAuthor Commented:
But its this pattern i'm trying to get too work:

"(?i)\bbox\ |post|private|\bpo\ |\bpobox|\bbag\ |p\.o$"
0
Rey Obrero (Capricorn1)Commented:
try this

.Pattern ="(i?)\bbox\ |post|private|\bpo\ |\bpobox|\bbag\ |p\.o$"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SeanNijAuthor Commented:
YIPPEEEEE

what is the diff between ?i and i?
0
Rey Obrero (Capricorn1)Commented:
?    -- Matches 0 or 1 instances of preceding character
--------------------------------------------^^^^^^
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.