Search a string

I

iris

Hi everybody,

I have created a userform in word that drows it's data from an access
database.

I need to do a search of a string inside the value of a database...

for example -

I have a :

userform1 with textbox1 and a search button1.

the userform is fed from a database - db1, table1, City (column)

in the textbox I want to search for the City name, not only for the first
letter - but according to any string I want... for example: if the name of
the City is New-york, I want to search for the string "yo" or for the string
"rk"...

can you show me how it's is done?

Thank You So very much!

Iris
 
G

Greg Maxey

Iris,

I am not sure exactly what it is that you want to do or if it can even be
done. However, you can use VBA logic to identify a string within a string.
For example:

Sub ScratchMacro()
Dim pStr As String
pStr = "New York City"
If InStr("New York City", "rk") > 0 Then
MsgBox "String found in string"
End If
End Sub
 
I

iris

I have this:

Str = "*" & textbox16.Text & "*"

Set rst = Database.OpenRecordset("select * from expressions WHERE hebrt LIKE
'" & Str & "';", dbOpenSnapshot)

if I type the number 6 in textbox16.text

msgbox str is *6*

is that something I can work with?
 
G

Greg Maxey

Iris,

Again, I can't say that I understand what it is that you are trying to do.

If your are asking if you can type something like "Yo" or "rk" into a
textfield of a Userform and then have the userform go off and pull data from
a column in a Database named "New York City" then yes, I suppose so:

Sub Whatever()
Dim pStr As String
If InStr(Me.textbox16.Text, "Yo") > 0 Or Instr(Me.textboxt16.Text, "rk") > 0
Then
pStr = "New York City"
End If

I know very little about database and nothing about what this specific code
would do but I suppose it would get data from the column titled New York
City

Set rst = Database.OpenRecordset("select * from expressions WHERE hebrt LIKE
'" & Str & "';", dbOpenSnapshot)
 
I

iris

Thank you Greg!

Althogh you say you know little about database... the pointers you gave me
hrlped a lot!

thank you again and have a nice weekend!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top