OpenForm problems

D

dangerkeepoff

Hi,
I need to open a new form that shows records with partial field matches to a
field in the original form. So far I have:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Find"
stLinkCriteria = "[Title] like" & "*" & [titlefind] & "*"

DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria

I have tried just about everything I can think off but will only either all
records or no records. I have tried not setting the WHERE criteria as a
string but using Me.titlefind in OpenForm.

Any help would be greatly appreciated

Thanks
 
L

Linq Adams via AccessMonster.com

Just for kicks, try placing a space after the LIKE

Instead of

"[Title] like"

try

"[Title] like "
 
F

fredg

Hi,
I need to open a new form that shows records with partial field matches to a
field in the original form. So far I have:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Find"
stLinkCriteria = "[Title] like" & "*" & [titlefind] & "*"

DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria

I have tried just about everything I can think off but will only either all
records or no records. I have tried not setting the WHERE criteria as a
string but using Me.titlefind in OpenForm.

Any help would be greatly appreciated

Thanks

Whenever you have a problem similar to this, it pays to have a msgbox
that will show you the actual value of the string you are using.

stLinkCriteria = "[Title] like" & "*" & [titlefind] & "*"
MsgBox stLinkCriteria
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria

Using your syntax, assuming "Smith" was the [titleFind] value,
the msgbox will show, for example,

[Title] like*Smith*

which is not a valid syntax.
1) There is no space between Like and the *
2) The *Smith* must be enclosed in quotes (')

Change your syntax to the following to add a space after the word like
and to include single quotes in front of the first asterisk and after
the second one ('*Smith*') .:

stLinkCriteria = "[Title] like" & "'*" & [titlefind] & "*'"

Which returns
[Title] like '*Smith*'

It should now open the form to the correct records.
When you have the syntax correct, delete the msgbox code.
 
D

dangerkeepoff via AccessMonster.com

Great thanks! working fine now.

Cheers
Hi,
I need to open a new form that shows records with partial field matches to a
[quoted text clipped - 15 lines]

Whenever you have a problem similar to this, it pays to have a msgbox
that will show you the actual value of the string you are using.

stLinkCriteria = "[Title] like" & "*" & [titlefind] & "*"
MsgBox stLinkCriteria
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria

Using your syntax, assuming "Smith" was the [titleFind] value,
the msgbox will show, for example,

[Title] like*Smith*

which is not a valid syntax.
1) There is no space between Like and the *
2) The *Smith* must be enclosed in quotes (')

Change your syntax to the following to add a space after the word like
and to include single quotes in front of the first asterisk and after
the second one ('*Smith*') .:

stLinkCriteria = "[Title] like" & "'*" & [titlefind] & "*'"

Which returns
[Title] like '*Smith*'

It should now open the form to the correct records.
When you have the syntax correct, delete the msgbox code.
 

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