Still trying to look up data with *

E

Edm

Im trying to use an unbound text box to look up data in a
table using the formats *Data, *data*, or data*. Ive
tried multiple variations of the code below, to no
success. Obviously Im missing something. Besides the
time to go to community college and take a class, what is
it though? =)

Here is the code. Any takers?

Dim stDocName As String
Dim ssDocName As String
Dim stLinkCriteria As String
Dim ssLinkCriteria As String

stDocName = "STOCK_WHSE27"
ssDocName = "STOCK_OUT"

ssLinkCriteria = "[Model Number]=" Like "*" & Me!
[Text1] & "*"
DoCmd.OpenForm ssDocName, , , ssLinkCriteria

stLinkCriteria = "[Model Number]=" Like "*" & Me!
[Text1] & "*"
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.RunCommand acCmdTileHorizontally



Thanks,

Edm
 
G

George Nicholson

You want the finished string to look something like this:
"[Model Number] Like '*data*'"

Note1: the above string ends with a single quote followed by a double quote.
Note2: "[ModelNumber] Like x", NOT "[ModelNumber] = Like x". Like takes the
place of the equal sign, don't use both.

so, try:
ssLinkCriteria = "[Model Number] Like '*" & Me! [Text1] & "*'"

HTH,
George Nicholson

Remove 'Junk' from return address.
 
F

fredg

Im trying to use an unbound text box to look up data in a
table using the formats *Data, *data*, or data*. Ive
tried multiple variations of the code below, to no
success. Obviously Im missing something. Besides the
time to go to community college and take a class, what is
it though? =)

Here is the code. Any takers?

Dim stDocName As String
Dim ssDocName As String
Dim stLinkCriteria As String
Dim ssLinkCriteria As String

stDocName = "STOCK_WHSE27"
ssDocName = "STOCK_OUT"

ssLinkCriteria = "[Model Number]=" Like "*" & Me!
[Text1] & "*"
DoCmd.OpenForm ssDocName, , , ssLinkCriteria

stLinkCriteria = "[Model Number]=" Like "*" & Me!
[Text1] & "*"
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.RunCommand acCmdTileHorizontally

Thanks,

Edm

The Criteria are not written correctly.

Is [ModelNumber] a Text Datatype field?

stLinkCriteria = "[Model Number] Like '*" & Me![Text1] & "*'"
ssLinkCriteria = "[Model Number] Like '*" & Me![Text1] & "*'"

will return all records in which the value of [Text1] is included
anywhere in the field, i.e. if [Text1] = 456, then Model Numbers
586456, 4569821,and 123456789 will all be returned in the form.

And it looks to me as though both stLinkCriteria and ssLinkCriteria
are exactly the same. Why use 2 different criteria variables?
Dim stDocName As String
Dim ssDocName As String
Dim stLinkCriteria As String

DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.OpenForm ssDocName, , , stLinkCriteria


You can make this all a bit easier to read if you don't use the
variables at all. They aren't necessary in this case.

DoCmd.OpenForm "STOCK_WHSE27", , , "[Model Number] Like '*" &
Me![Text1] & "*'"
DoCmd.OpenForm "STOCK_OUT", , , "[Model Number] Like '*" & Me![Text1]
& "*'"
 
E

Edm

Perfect solutions.

-----Original Message-----
You want the finished string to look something like this:
"[Model Number] Like '*data*'"

Note1: the above string ends with a single quote followed by a double quote.
Note2: "[ModelNumber] Like x", NOT "[ModelNumber] = Like x". Like takes the
place of the equal sign, don't use both.

so, try:
ssLinkCriteria = "[Model Number] Like '*" & Me! [Text1] & "*'"

HTH,
George Nicholson

Remove 'Junk' from return address.


Im trying to use an unbound text box to look up data in a
table using the formats *Data, *data*, or data*. Ive
tried multiple variations of the code below, to no
success. Obviously Im missing something. Besides the
time to go to community college and take a class, what is
it though? =)

Here is the code. Any takers?

Dim stDocName As String
Dim ssDocName As String
Dim stLinkCriteria As String
Dim ssLinkCriteria As String

stDocName = "STOCK_WHSE27"
ssDocName = "STOCK_OUT"

ssLinkCriteria = "[Model Number]=" Like "*" & Me!
[Text1] & "*"
DoCmd.OpenForm ssDocName, , , ssLinkCriteria

stLinkCriteria = "[Model Number]=" Like "*" & Me!
[Text1] & "*"
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.RunCommand acCmdTileHorizontally



Thanks,

Edm


.
 

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