B
BDCC
Is there a way of searching a field for a certain text string and then
pulling the next 11 characters into a new field during a query?
pulling the next 11 characters into a new field during a query?
HSalim said:Here is the answer you are looking for:
Public Function Next11(StringToSearch As String, StringToFind As String) As
String
Dim RetVal As String, Nums As String
'This line will extract the next 11 chars after string to find
'retval = Mid(StringToSearch, InStr(1, StringToSearch, StringToFind,
vbTextCompare) + Len(StringToFind), 11)
'this line will extract all chars after the string to find
RetVal = Mid(StringToSearch, InStr(1, StringToSearch, StringToFind,
vbTextCompare) + Len(StringToFind))
'Set a reference to the Regular Expression object
' You Must add a reference to Microsoft VBScript Regular Expressions 5.5
Dim regEx As New RegExp
regEx.Pattern = "\D" 'Set the pattern as all non digits
regEx.Global = True 'Find all matches. False finds only the first match
'Replace all non-digits
Nums = regEx.Replace(RetVal, replval)
' Get the next 11 numbers - Not required if retval has been cut down earlier
you could just use retval = nums
RetVal = Left(Nums, 11)
Next11 = RetVal
End Function
-----------------------------------------------------------
BDCC,
Yes, you may ask for more assistance, but please post your questions to the
newsgroup - others might benefit from that as well.
And please do not request read receipts on mails to me.
HS
-----Original Message-----
From: BDCC [mailto:[email protected]]
Sent: Wednesday, August 13, 2003 11:31 AM
To: (e-mail address removed)
Subject: Re: help required
Great this is exactly what I was looking for, but can I be cheeky and ask
you to refine the function slightly. The field I'm searching through
contains all manner of characters including line fields etc. In the eleven
character string it finds can it filter out all characters except numbers?
Any help would be appreciated.
Thanks
HSalim said:Add this function to a code module.
Public Function Next11(StringToSearch As String, StringToFind As String) As
String
Dim retval As String
retval = Mid(StringToSearch, InStr(1, StringToSearch, StringToFind ,
vbTextCompare) + Len(StringToFind ), 11)
Next11 = retval
End Function
you can now use this in code or in a query
Example
temp = Next11("abcdefghijklmnopqrstuv", "bcd")
temp = Next11(me.SomeTextbox, "bcd")
in a query
SomeColumnName: Next11(SomeFieldName, "bcd")
BDCC said:I tried to put this in but it comes up with the following error 'Compile
error user defined type not defined' on the line 'Dim regEx As New RegExp'.
Any ideas?
HSalim said:Here is the answer you are looking for:
Public Function Next11(StringToSearch As String, StringToFind As String) As
String
Dim RetVal As String, Nums As String
'This line will extract the next 11 chars after string to find
'retval = Mid(StringToSearch, InStr(1, StringToSearch, StringToFind,
vbTextCompare) + Len(StringToFind), 11)
'this line will extract all chars after the string to find
RetVal = Mid(StringToSearch, InStr(1, StringToSearch, StringToFind,
vbTextCompare) + Len(StringToFind))
'Set a reference to the Regular Expression object
' You Must add a reference to Microsoft VBScript Regular Expressions 5.5
Dim regEx As New RegExp
regEx.Pattern = "\D" 'Set the pattern as all non digits
regEx.Global = True 'Find all matches. False finds only the first match
'Replace all non-digits
Nums = regEx.Replace(RetVal, replval)
' Get the next 11 numbers - Not required if retval has been cut down earlier
you could just use retval = nums
RetVal = Left(Nums, 11)
Next11 = RetVal
End Function
-----------------------------------------------------------
BDCC,
Yes, you may ask for more assistance, but please post your questions to the
newsgroup - others might benefit from that as well.
And please do not request read receipts on mails to me.
HS
-----Original Message-----
From: BDCC [mailto:[email protected]]
Sent: Wednesday, August 13, 2003 11:31 AM
To: (e-mail address removed)
Subject: Re: help required
Great this is exactly what I was looking for, but can I be cheeky and ask
you to refine the function slightly. The field I'm searching through
contains all manner of characters including line fields etc. In the eleven
character string it finds can it filter out all characters except numbers?
Any help would be appreciated.
Thanks
String)HSalim said:Add this function to a code module.
Public Function Next11(StringToSearch As String, StringToFind As
AsString
Dim retval As String
retval = Mid(StringToSearch, InStr(1, StringToSearch, StringToFind ,
vbTextCompare) + Len(StringToFind ), 11)
Next11 = retval
End Function
you can now use this in code or in a query
Example
temp = Next11("abcdefghijklmnopqrstuv", "bcd")
temp = Next11(me.SomeTextbox, "bcd")
in a query
SomeColumnName: Next11(SomeFieldName, "bcd")
Is there a way of searching a field for a certain text string and then
pulling the next 11 characters into a new field during a query?
BDCC said:Sorry being a bit thick. I'm new to Access, VB etc, how do you do this??
HSalim said:If you had read the code you would have seen5.5' You Must add a reference to Microsoft VBScript Regular Expressions
andBDCC said:I tried to put this in but it comes up with the following error 'Compile
error user defined type not defined' on the line 'Dim regEx As New RegExp'.
Any ideas?
Here is the answer you are looking for:
Public Function Next11(StringToSearch As String, StringToFind As String)
As
String
Dim RetVal As String, Nums As String
'This line will extract the next 11 chars after string to find
'retval = Mid(StringToSearch, InStr(1, StringToSearch, StringToFind,
vbTextCompare) + Len(StringToFind), 11)
'this line will extract all chars after the string to find
RetVal = Mid(StringToSearch, InStr(1, StringToSearch, StringToFind,
vbTextCompare) + Len(StringToFind))
'Set a reference to the Regular Expression object
' You Must add a reference to Microsoft VBScript Regular Expressions 5.5
Dim regEx As New RegExp
regEx.Pattern = "\D" 'Set the pattern as all non digits
regEx.Global = True 'Find all matches. False finds only the first match
'Replace all non-digits
Nums = regEx.Replace(RetVal, replval)
' Get the next 11 numbers - Not required if retval has been cut down
earlier
you could just use retval = nums
RetVal = Left(Nums, 11)
Next11 = RetVal
End Function
-----------------------------------------------------------
BDCC,
Yes, you may ask for more assistance, but please post your questions to
the
newsgroup - others might benefit from that as well.
And please do not request read receipts on mails to me.
HS
-----Original Message-----
From: BDCC [mailto:[email protected]]
Sent: Wednesday, August 13, 2003 11:31 AM
To: (e-mail address removed)
Subject: Re: help required
Great this is exactly what I was looking for, but can I be cheeky
askandyou to refine the function slightly. The field I'm searching through
contains all manner of characters including line fields etc. In the
eleven
character string it finds can it filter out all characters except numbers?
Any help would be appreciated.
Thanks
Add this function to a code module.
Public Function Next11(StringToSearch As String, StringToFind As String)
As
String
Dim retval As String
retval = Mid(StringToSearch, InStr(1, StringToSearch, StringToFind ,
vbTextCompare) + Len(StringToFind ), 11)
Next11 = retval
End Function
you can now use this in code or in a query
Example
temp = Next11("abcdefghijklmnopqrstuv", "bcd")
temp = Next11(me.SomeTextbox, "bcd")
in a query
SomeColumnName: Next11(SomeFieldName, "bcd")
Is there a way of searching a field for a certain text string
thenpulling the next 11 characters into a new field during a query?
BDCC said:Gives an error on the line 'Next11 = RetVal'. Help!!
StringToFindHSalim said:Change the return value's type from String to Long. i.e. change to
Public Function Next11(StringToSearch As String, StringToFind As String)
As Long
This will automatically strip the leading zeros
good luck
cutBDCC said:I need a slight alteration to the code. Once it has got the string of
numbers, I now need it to remove all preceeding 0's (zero's), how can this
be done??
thanks
Sorry being a bit thick. I'm new to Access, VB etc, how do you do this??
If you had read the code you would have seen
' You Must add a reference to Microsoft VBScript Regular Expressions
5.5
I tried to put this in but it comes up with the following error
'Compile
error user defined type not defined' on the line 'Dim regEx As New
RegExp'.
Any ideas?
Here is the answer you are looking for:
Public Function Next11(StringToSearch As String, StringToFind As
String)
As
String
Dim RetVal As String, Nums As String
'This line will extract the next 11 chars after string to find
'retval = Mid(StringToSearch, InStr(1, StringToSearch, StringToFind,
vbTextCompare) + Len(StringToFind), 11)
'this line will extract all chars after the string to find
RetVal = Mid(StringToSearch, InStr(1, StringToSearch, StringToFind,
vbTextCompare) + Len(StringToFind))
'Set a reference to the Regular Expression object
' You Must add a reference to Microsoft VBScript Regular Expressions
5.5
Dim regEx As New RegExp
regEx.Pattern = "\D" 'Set the pattern as all non digits
regEx.Global = True 'Find all matches. False finds only the first
match
'Replace all non-digits
Nums = regEx.Replace(RetVal, replval)
' Get the next 11 numbers - Not required if retval has been
downInearlier
you could just use retval = nums
RetVal = Left(Nums, 11)
Next11 = RetVal
End Function
-----------------------------------------------------------
BDCC,
Yes, you may ask for more assistance, but please post your questions
to
the
newsgroup - others might benefit from that as well.
And please do not request read receipts on mails to me.
HS
-----Original Message-----
From: BDCC [mailto:[email protected]]
Sent: Wednesday, August 13, 2003 11:31 AM
To: (e-mail address removed)
Subject: Re: help required
Great this is exactly what I was looking for, but can I be cheeky
and
ask
you to refine the function slightly. The field I'm searching
through
contains all manner of characters including line fields etc.
theeleven
character string it finds can it filter out all characters except
numbers?
Any help would be appreciated.
Thanks
Add this function to a code module.
Public Function Next11(StringToSearch As String,
BDCC said:It didn't work, gives the error 'type mismatch', any more ideas?
stringBrendan Reynolds (MVP) said:Try Next11 = CLng(RetVal)ofAsnumbers, I now need it to remove all preceeding 0's (zero's), how can
this
be done??
thanks
Sorry being a bit thick. I'm new to Access, VB etc, how do you do
this??
If you had read the code you would have seen
' You Must add a reference to Microsoft VBScript Regular
Expressions
5.5
I tried to put this in but it comes up with the following error
'Compile
error user defined type not defined' on the line 'Dim regEx
NewStringToFindRegExp'.
Any ideas?
Here is the answer you are looking for:
Public Function Next11(StringToSearch As String,beenAs
String)
As
String
Dim RetVal As String, Nums As String
'This line will extract the next 11 chars after string to find
'retval = Mid(StringToSearch, InStr(1, StringToSearch,
StringToFind,
vbTextCompare) + Len(StringToFind), 11)
'this line will extract all chars after the string to find
RetVal = Mid(StringToSearch, InStr(1, StringToSearch,
StringToFind,
vbTextCompare) + Len(StringToFind))
'Set a reference to the Regular Expression object
' You Must add a reference to Microsoft VBScript Regular
Expressions
5.5
Dim regEx As New RegExp
regEx.Pattern = "\D" 'Set the pattern as all non digits
regEx.Global = True 'Find all matches. False finds only the
first
match
'Replace all non-digits
Nums = regEx.Replace(RetVal, replval)
' Get the next 11 numbers - Not required if retval has
cutetc.down
earlier
you could just use retval = nums
RetVal = Left(Nums, 11)
Next11 = RetVal
End Function
-----------------------------------------------------------
BDCC,
Yes, you may ask for more assistance, but please post your
questions
to
the
newsgroup - others might benefit from that as well.
And please do not request read receipts on mails to me.
HS
-----Original Message-----
From: BDCC [mailto:[email protected]]
Sent: Wednesday, August 13, 2003 11:31 AM
To: (e-mail address removed)
Subject: Re: help required
Great this is exactly what I was looking for, but can I be
cheeky
and
ask
you to refine the function slightly. The field I'm searching
through
contains all manner of characters including line fields
Inthe
eleven
character string it finds can it filter out all characters
except
numbers?
Any help would be appreciated.
Thanks
Add this function to a code module.
Public Function Next11(StringToSearch As String, StringToFind
As
String)
As
String
Dim retval As String
retval = Mid(StringToSearch, InStr(1, StringToSearch,
StringToFind
,
vbTextCompare) + Len(StringToFind ), 11)
Next11 = retval
End Function
you can now use this in code or in a query
Example
temp = Next11("abcdefghijklmnopqrstuv", "bcd")
temp = Next11(me.SomeTextbox, "bcd")
in a query
SomeColumnName: Next11(SomeFieldName, "bcd")
Is there a way of searching a field for a certain text
string
and
then
pulling the next 11 characters into a new field during a
query?
Brendan Reynolds (MVP) said:It's getting a bit confusing reading back through the previous posts and
trying to picture what the code looks like at this stage. Could you post the
code as it is now, and indicate on which line it breaks?
--
Brendan Reynolds (Access MVP)
(e-mail address removed)
regExBDCC said:It didn't work, gives the error 'type mismatch', any more ideas?
string how
canduringAstoNew
RegExp'.
Any ideas?
Here is the answer you are looking for:
Public Function Next11(StringToSearch As String, StringToFind
As
String)
As
String
Dim RetVal As String, Nums As String
'This line will extract the next 11 chars after string
findonly'retval = Mid(StringToSearch, InStr(1, StringToSearch,
StringToFind,
vbTextCompare) + Len(StringToFind), 11)
'this line will extract all chars after the string to find
RetVal = Mid(StringToSearch, InStr(1, StringToSearch,
StringToFind,
vbTextCompare) + Len(StringToFind))
'Set a reference to the Regular Expression object
' You Must add a reference to Microsoft VBScript Regular
Expressions
5.5
Dim regEx As New RegExp
regEx.Pattern = "\D" 'Set the pattern as all non digits
regEx.Global = True 'Find all matches. False finds
thefirst
match
'Replace all non-digits
Nums = regEx.Replace(RetVal, replval)
' Get the next 11 numbers - Not required if retval has been
cut
down
earlier
you could just use retval = nums
RetVal = Left(Nums, 11)
Next11 = RetVal
End Function
-----------------------------------------------------------
BDCC,
Yes, you may ask for more assistance, but please post your
questions
to
the
newsgroup - others might benefit from that as well.
And please do not request read receipts on mails to me.
HS
-----Original Message-----
From: BDCC [mailto:[email protected]]
Sent: Wednesday, August 13, 2003 11:31 AM
To: (e-mail address removed)
Subject: Re: help required
Great this is exactly what I was looking for, but can I be
cheeky
and
ask
you to refine the function slightly. The field I'm searching
through
contains all manner of characters including line fields etc.
In
the
eleven
character string it finds can it filter out all characters
except
numbers?
Any help would be appreciated.
Thanks
Add this function to a code module.
Public Function Next11(StringToSearch As String,
StringToFind
As
String)
As
String
Dim retval As String
retval = Mid(StringToSearch, InStr(1, StringToSearch,
StringToFind
,
vbTextCompare) + Len(StringToFind ), 11)
Next11 = retval
End Function
you can now use this in code or in a query
Example
temp = Next11("abcdefghijklmnopqrstuv", "bcd")
temp = Next11(me.SomeTextbox, "bcd")
in a query
SomeColumnName: Next11(SomeFieldName, "bcd")
Is there a way of searching a field for a certain text
string
and
then
pulling the next 11 characters into a new field
HSalim said:I just tried it and did not get a type mismstch. I did get an overflow
error though.
Since you are interested in a max of 11 numbers, you can use the currency
data type or a double
Anyway, here is the function again.
next11("dkdkb0001234512345rkr","kb") returns 12345123
HS
----------------------------
Public Function Next11(StringToSearch As String, StringToFind As String) As
Currency
Dim RetVal As String, Nums As String
'This line will extract the next 11 chars after string to find
'retval = Mid(StringToSearch, InStr(1, StringToSearch, StringToFind,
vbTextCompare) + Len(StringToFind), 11)
'this line will extract all chars after the string to find
RetVal = Mid(StringToSearch, InStr(1, StringToSearch, StringToFind,
vbTextCompare) + Len(StringToFind))
'Set a reference to the Regular Expression object
' You Must add a reference to Microsoft VBScript Regular Expressions 5.5
Dim regEx As New RegExp
regEx.Pattern = "\D" 'Set the pattern as all non digits
regEx.Global = True 'Find all matches. False finds only the first match
'Replace all non-digits
Nums = regEx.Replace(RetVal, replval)
' Get the next 11 numbers - Not required if retval has been cut down earlier
RetVal = (Left(Nums, 11))
Next11 = CCur(RetVal)
End Function
-----------------------------
StringToFindBrendan Reynolds (MVP) said:It's getting a bit confusing reading back through the previous posts and
trying to picture what the code looks like at this stage. Could you post the
code as it is now, and indicate on which line it breaks?IAsyouString)
As Long
This will automatically strip the leading zeros
good luck
I need a slight alteration to the code. Once it has got the string
of
numbers, I now need it to remove all preceeding 0's (zero's), how
can
this
be done??
thanks
Sorry being a bit thick. I'm new to Access, VB etc, how do
doregExthis??
If you had read the code you would have seen
' You Must add a reference to Microsoft VBScript Regular
Expressions
5.5
I tried to put this in but it comes up with the following
error
'Compile
error user defined type not defined' on the line 'DimAs
New
RegExp'.
Any ideas?
Here is the answer you are looking for:
Public Function Next11(StringToSearch As String,
StringToFind
As
String)
As
String
Dim RetVal As String, Nums As String
'This line will extract the next 11 chars after string to
find
'retval = Mid(StringToSearch, InStr(1, StringToSearch,
StringToFind,
vbTextCompare) + Len(StringToFind), 11)
'this line will extract all chars after the string to find
RetVal = Mid(StringToSearch, InStr(1, StringToSearch,
StringToFind,
vbTextCompare) + Len(StringToFind))
'Set a reference to the Regular Expression object
' You Must add a reference to Microsoft VBScript Regular
Expressions
5.5
Dim regEx As New RegExp
regEx.Pattern = "\D" 'Set the pattern as all non digits
regEx.Global = True 'Find all matches. False finds only
the
first
match
'Replace all non-digits
Nums = regEx.Replace(RetVal, replval)
' Get the next 11 numbers - Not required if retval has been
cut
down
earlier
you could just use retval = nums
RetVal = Left(Nums, 11)
Next11 = RetVal
End Function
-----------------------------------------------------------
BDCC,
Yes, you may ask for more assistance, but please post your
questions
to
the
newsgroup - others might benefit from that as well.
And please do not request read receipts on mails to me.
HS
-----Original Message-----
From: BDCC [mailto:[email protected]]
Sent: Wednesday, August 13, 2003 11:31 AM
To: (e-mail address removed)
Subject: Re: help required
Great this is exactly what I was looking for, but canbe fields
etc. during
Is there a way of searching a field for a certain text string and then
pulling the next 11 characters into a new field during a query?
Great this is exactly what I was looking for, but can I be cheeky and ask
you to refine the function slightly. The field I'm searching through
contains all manner of characters including line fields etc. In the eleven
character string it finds can it filter out all characters except numbers?