C
Chris Crook
Hey everyone,
I have just started using VBA in Access like a week ago, because I am
sure it is the only way to make my database work. What I am trying to
do is create a function that will be within the criteria of a query.
I am trying to write a replace function where a user can type in two
words to search separated by AND. The replace function will then look
for " AND ", replacing it with
(" & ""*"" AND LIKE ""*"" & "). The whole criteria line will look
like this:
Like "*" & [fncReplacetxt()] & "*".
My code for the replace function looks like this (it is probably
wrong, cause I just started writing code yesterday):
Public Function ReplaceTxt(inputtxt As String) As String
Dim inputtxtAnd As String
Dim inputtxtNot As String
Dim inputtxtOr As String
inputtxt = Replace(inputtxt, " AND ", " & ""*"" AND LIKE ""*"" &
")
inputtxtAnd = Replace(inputtxtAnd, " NOT ", " & ""*"" NOT LIKE
""*"" & ")
inputtxtNot = Replace(inputtxtNot, " OR ", " & ""*"" OR LIKE ""*""
& ")
ReplaceTxt = inputtxtOr
End Function
I know it's not, but assuming this function is OK, how can I get the
text entered by a user on a form to go thru this function and be
implanted in the query criteria??
Any help is greatly appreciated!
Cheers,
Chris
I have just started using VBA in Access like a week ago, because I am
sure it is the only way to make my database work. What I am trying to
do is create a function that will be within the criteria of a query.
I am trying to write a replace function where a user can type in two
words to search separated by AND. The replace function will then look
for " AND ", replacing it with
(" & ""*"" AND LIKE ""*"" & "). The whole criteria line will look
like this:
Like "*" & [fncReplacetxt()] & "*".
My code for the replace function looks like this (it is probably
wrong, cause I just started writing code yesterday):
Public Function ReplaceTxt(inputtxt As String) As String
Dim inputtxtAnd As String
Dim inputtxtNot As String
Dim inputtxtOr As String
inputtxt = Replace(inputtxt, " AND ", " & ""*"" AND LIKE ""*"" &
")
inputtxtAnd = Replace(inputtxtAnd, " NOT ", " & ""*"" NOT LIKE
""*"" & ")
inputtxtNot = Replace(inputtxtNot, " OR ", " & ""*"" OR LIKE ""*""
& ")
ReplaceTxt = inputtxtOr
End Function
I know it's not, but assuming this function is OK, how can I get the
text entered by a user on a form to go thru this function and be
implanted in the query criteria??
Any help is greatly appreciated!
Cheers,
Chris