visual basic help...

G

Guest

Hi, i have a search form set up with the following search textbox fields named:

keyword1
subject

and a combobox named:

topic

they are all related to "table 1" columns named [key words], [subjects],
[topic]

i want to make the text fields have the ability to search using any amount
of the word, and i want to make it so that they can fill out all or just one
of the search criteria. this is what i have so far.... and it keeps giving me
a syntax error.... and wont show the search results.... can someone tell me
where i went wrong with my coding?

thanks

Em~~

Private Sub cmdsearch_click()
Dim strwhere As String
Dim inglen As Long

If Not IsNull(Me.keyword1) Then
strwhere = strwhere & "([key words] = """ & Me.keyword1 & """) AND "
End If

If Not IsNull(Me.subject) Then
strwhere = strwhere & "([subjects] = """ & Me.subject & """) AND "
End If

If Not IsNull(Me.topic) Then
strwhere = strwhere & "([topics] = "" & Me.topic & "") AND "
End If

inglen = Len(strwhere) - 5
If inglen <= 0 Then
MsgBox "no criteria"
Else
strwhere = Left$(strwhere, inglen)
Me.filter = strwhere 'THIS IS WHERE IT KEEPS SENDING ME TO DEBUG...'
Me.FilterOn = True
End If

End Sub
 
G

Guest

Thanks Doug,
lets say i type in "filter" as my search word in the keywords section:

the value it gives me to type in to debug the error is:
'Me.Filter = "([key words]like "filt""

it does the same thing if i try to type a word into the subject box....

something must be wrong with my coding of the text boxes, b/c i want them to
search using any amount of the letters in a word... im confused here

so im not sure what i did wrong!

Thanks,

Em~

Douglas J. Steele said:
What's the value of strWhere when you get the problem?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


emmy128 said:
Hi, i have a search form set up with the following search textbox fields
named:

keyword1
subject

and a combobox named:

topic

they are all related to "table 1" columns named [key words], [subjects],
[topic]

i want to make the text fields have the ability to search using any amount
of the word, and i want to make it so that they can fill out all or just
one
of the search criteria. this is what i have so far.... and it keeps giving
me
a syntax error.... and wont show the search results.... can someone tell
me
where i went wrong with my coding?

thanks

Em~~

Private Sub cmdsearch_click()
Dim strwhere As String
Dim inglen As Long

If Not IsNull(Me.keyword1) Then
strwhere = strwhere & "([key words] = """ & Me.keyword1 & """) AND "
End If

If Not IsNull(Me.subject) Then
strwhere = strwhere & "([subjects] = """ & Me.subject & """) AND "
End If

If Not IsNull(Me.topic) Then
strwhere = strwhere & "([topics] = "" & Me.topic & "") AND "
End If

inglen = Len(strwhere) - 5
If inglen <= 0 Then
MsgBox "no criteria"
Else
strwhere = Left$(strwhere, inglen)
Me.filter = strwhere 'THIS IS WHERE IT KEEPS SENDING ME TO DEBUG...'
Me.FilterOn = True
End If

End Sub
 
D

Douglas J. Steele

Given that your code has =, not like in it, I don't see how you could be
getting that value for the filter!

What I really wanted you to do was put the line

Debug.Print strwhere

directly in front of the line

Me.filter = strwhere

and then go to the Immediate window (Ctrl-G), copy what was printed there
and paste it into your reply.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


emmy128 said:
Thanks Doug,
lets say i type in "filter" as my search word in the keywords section:

the value it gives me to type in to debug the error is:
'Me.Filter = "([key words]like "filt""

it does the same thing if i try to type a word into the subject box....

something must be wrong with my coding of the text boxes, b/c i want them
to
search using any amount of the letters in a word... im confused here

so im not sure what i did wrong!

Thanks,

Em~

Douglas J. Steele said:
What's the value of strWhere when you get the problem?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


emmy128 said:
Hi, i have a search form set up with the following search textbox
fields
named:

keyword1
subject

and a combobox named:

topic

they are all related to "table 1" columns named [key words],
[subjects],
[topic]

i want to make the text fields have the ability to search using any
amount
of the word, and i want to make it so that they can fill out all or
just
one
of the search criteria. this is what i have so far.... and it keeps
giving
me
a syntax error.... and wont show the search results.... can someone
tell
me
where i went wrong with my coding?

thanks

Em~~

Private Sub cmdsearch_click()
Dim strwhere As String
Dim inglen As Long

If Not IsNull(Me.keyword1) Then
strwhere = strwhere & "([key words] = """ & Me.keyword1 & """) AND "
End If

If Not IsNull(Me.subject) Then
strwhere = strwhere & "([subjects] = """ & Me.subject & """) AND "
End If

If Not IsNull(Me.topic) Then
strwhere = strwhere & "([topics] = "" & Me.topic & "") AND "
End If

inglen = Len(strwhere) - 5
If inglen <= 0 Then
MsgBox "no criteria"
Else
strwhere = Left$(strwhere, inglen)
Me.filter = strwhere 'THIS IS WHERE IT KEEPS SENDING ME TO DEBUG...'
Me.FilterOn = True
End If

End Sub
 

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