bear23
asked on
Visual basic find word in a database record and pull data after it
I have a database with a MEMO field. I need a code to find a certain word in the record and if found pull the data to the right of it. if not then do nothing and go to the next record.
Example.
field1 field2
1 this is a test and the word is great to be alive. How are you today
2 today is friday and it is the week end
what I have here is two records.
I need it to look at the first record and find the word -----to
once found then copy the next 6 character would be:space be al
counting spaces this is how I get 6 characters
then go to the next record.
since-----to---- is not in the record do nothing. and so on until the records are all looked at.
Is this possible.
Platform = Visual Basic 6
adodb = Microsoft Access database
Example.
field1 field2
1 this is a test and the word is great to be alive. How are you today
2 today is friday and it is the week end
what I have here is two records.
I need it to look at the first record and find the word -----to
once found then copy the next 6 character would be:space be al
counting spaces this is how I get 6 characters
then go to the next record.
since-----to---- is not in the record do nothing. and so on until the records are all looked at.
Is this possible.
Platform = Visual Basic 6
adodb = Microsoft Access database
the problem with the is let say this
I want to use another key word
td
and I have records like this
this is td2 great day
hello td I hate today
it seems like even though I have td listed it is pulling the td2
is there a way to just make it look for td2 not anything other
I want to use another key word
td
and I have records like this
this is td2 great day
hello td I hate today
it seems like even though I have td listed it is pulling the td2
is there a way to just make it look for td2 not anything other
ASKER
geez peanut, you have been following me. this is the second or third question. Are you testing experts or are you just having the same problems????
ASKER
out of curiousity, because that might be a problem I face, what is the answer to that.
I tried what he was talking about and it seemed that if it seen any of the two character that it automatically pulled it. I even tried a if then statement and it still did it, meaning
keyword
to2
if InStr(1, DataBaseField, "to") > 0 then
InfoAfterTo = Mid(DataBaseField, InStr(1, DataBaseField, "to") + 2, 6)
else
msgbox "No Match"
end if
the result was not the msgbox like it should have been, it did the infoafterto
is there a way to just lock the only work "to2"
not "to", to23344", "to2r", etc
I tried what he was talking about and it seemed that if it seen any of the two character that it automatically pulled it. I even tried a if then statement and it still did it, meaning
keyword
to2
if InStr(1, DataBaseField, "to") > 0 then
InfoAfterTo = Mid(DataBaseField, InStr(1, DataBaseField, "to") + 2, 6)
else
msgbox "No Match"
end if
the result was not the msgbox like it should have been, it did the infoafterto
is there a way to just lock the only work "to2"
not "to", to23344", "to2r", etc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dabas is correct.
dragontooth
dragontooth
ASKER
the problem I am having now that I am really playing with it is the fact that if anywhere in that record there is the identifier it is pulling it.
So example
concentrating on this if part
key word this time is:
to
I have the following statement
if InStr(1, DataBaseField, "to") > 0 then
msgbox "found"
else
msgbox "No Match"
end if
record looks like this
I am going too
next record
I am going to the store
it is pulling msgbox found for both, it should only pull for the 2nd recordset
I am going to the store
why or how can I get this if then statement to work properly....
So example
concentrating on this if part
key word this time is:
to
I have the following statement
if InStr(1, DataBaseField, "to") > 0 then
msgbox "found"
else
msgbox "No Match"
end if
record looks like this
I am going too
next record
I am going to the store
it is pulling msgbox found for both, it should only pull for the 2nd recordset
I am going to the store
why or how can I get this if then statement to work properly....
As Dabas pointed out if you are looking for the word "to" and you do not want to pick up every occurance of "to" and you actually want to pick up the word " to " add spaces and adjust the count.
So in this case you will pick up every occurance of "to " in "away we go into the wild blue yonder" using the code below you will get a message box of "found"
if InStr(1, DataBaseField, "to ") > 0 then ' "to " you are looking for this
msgbox "found"
else
msgbox "No Match"
end if
So in this case you will pick up every occurance of " to " in "away we go into the wild blue yonder" using the code below you will get a message box of "No Match"
if InStr(1, DataBaseField, " to ") > 0 then ' " to " you are looking for this
msgbox "found"
else
msgbox "No Match"
end if
So in this case you will pick up every occurance of "to" in "away we go into the wild blue yonder" using the code below you will get a message box of "found"
if InStr(1, DataBaseField, "to") > 0 then ' "to" you are looking for this
msgbox "found"
else
msgbox "No Match"
end if
dragontooth
So in this case you will pick up every occurance of "to " in "away we go into the wild blue yonder" using the code below you will get a message box of "found"
if InStr(1, DataBaseField, "to ") > 0 then ' "to " you are looking for this
msgbox "found"
else
msgbox "No Match"
end if
So in this case you will pick up every occurance of " to " in "away we go into the wild blue yonder" using the code below you will get a message box of "No Match"
if InStr(1, DataBaseField, " to ") > 0 then ' " to " you are looking for this
msgbox "found"
else
msgbox "No Match"
end if
So in this case you will pick up every occurance of "to" in "away we go into the wild blue yonder" using the code below you will get a message box of "found"
if InStr(1, DataBaseField, "to") > 0 then ' "to" you are looking for this
msgbox "found"
else
msgbox "No Match"
end if
dragontooth
for each record
InfoAfterTo = Mid(DataBaseField, InStr(1, DataBaseField, "to") + 2, 6)
next
HTH
dragontooth