Bob P
Bob P

Reputation: 237

Why won't this VB and SQL work?

Private Sub Text46_AfterUpdate()

Dim strSource2 As String

strSource2 = "SELECT [Product Code],[Stock Level],[Description] FROM [products/stock]       WHERE [Product Code] LIKE " & "'%" & Me.Text46.Value & "%';"

Me.listSource.RowSource = strSource2
Me.listSource = vbNullString

End Sub

It is supposed to search the database for all products that have a product code matching the value of Text46 in some way, but I really cannot get it to work and I really don't know why. listSource is the listbox that I want the information to appear in.

Thanks in advance, Bob P

Upvotes: 1

Views: 59

Answers (1)

Fionnuala
Fionnuala

Reputation: 91376

In MS Access, the wildcard is * not %, unless you are working with ADO, or you have changed the ANSI standard in options.

"SELECT [Product Code],[Stock Level],[Description] " _
& "FROM [products/stock] " _
& "WHERE [Product Code] LIKE " & "'*" & Me.Text46.Value & "*';"

Upvotes: 4

Related Questions