Wildcard in WHERE

J

Jay

Hi,
Can anyone help?
I have a Access 97 database that I converted to XP.
This code works in 97:

Private Sub BUTTON5_CLICK()
Const MB_OK = 0, MB_OKCANCEL = 1, mb_ico 48'define buttons.
Const Quote = """"

Dim X As String
Dim Sqlstr As String

Sqlstr = "[Part] Like " & Quote & "*|forms! _&
[obsfrmQueryPart]![txtPart]|*" & Quote

X = DCount("[Part]", "obsolete", Sqlstr)

After the convesion X always comes up as 0, even on a
valid number. I rewrote it like this:

Private Sub BUTTON5_CLICK()
Const MB_OK = 0, MB_OKCANCEL = 1, mb_ico = 48

Dim X As String
Dim Sqlstr As String

Sqlstr = "[Part] Like '" & Forms![obsfrmQueryPart]!
[txtPart] & "'"

X = DCount("[Part]", "obsolete", Sqlstr)

It works with the whole number but any way I try to add
the wildcard it does not work at all!!??
Any ideas?
 
D

Douglas J. Steele

Sqlstr = "[Part] Like '*" & Forms![obsfrmQueryPart]![txtPart] & "*'"

Exagerated for clarity:

Sqlstr = "[Part] Like ' * " & Forms![obsfrmQueryPart]![txtPart] & " * ' "
 

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