Like('*') won't work in Access qry

M

msch-prv

I am trying to pull out data from an Access mdb via the Like()
operator. The code works fine for specific values ie 3, 4 but fails for
the '*' value.

TIA for any hints. Mark

Code excerpt: (ddnEmp.SelectedValue is a dropdown box, with values: 0,
1, 2 etc.)

Dim mstrConn As String =
ConfigurationManager.ConnectionStrings("DbConn").ConnectionString
Dim mobjConnection As New OleDbConnection(mstrConn)

Dim strFrom As String = ddnEmp.SelectedValue
Dim strSQL As String = "SELECT qryActByDay.*, * FROM qryActByDay WHERE
qryActByDay.ActFrom Like(@From);"

Dim objCommand As New OleDbCommand(strSQL, mobjConnection)

Dim prm As New OleDbParameter()
With prm
.ParameterName = "@From"
'If 0 show all data
If strFrom <> "0" Then .Value = strFrom Else .Value = "'*'"
End With
objCommand.Parameters.Add(prm)
 
M

msch-prv

Thanks for the feedback Edwin.

I tried with '%' , % ie Like(%), Like('%') to no avail. Mark
 
E

Edwin Knoppert

Try access first, i don't recognize the () stuff.
If access requires * then simply swap % for dotnet.
 
M

msch-prv

Nope, I removed the brackets and tried with '%', ' %*%' By the way,
Access doesn't mind about either Like('*') or Like '*'.
 
M

msch-prv

Edwin, my apologies. You were right! Somewhere in my code, input
ddnEmp.SelectedValue was tied to "'*'", which caused the code to fail.

The following does it:
If strFrom <> "0" Then .Value = strFrom Else .Value = "%"

Thanks again, Mark
 

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