• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

Access 2010 Like Function

I' using the following code:
DoCmd.OpenForm "frm_Legend", , , "[Symbol] Like " * "'" & Me.Scenario_Code & "'"

however I get an error message Run Time Error 13 Data Mismatch -- any thoughts on how to correct.
0
shieldsco
Asked:
shieldsco
  • 4
  • 4
1 Solution
 
PatHartmanCommented:
Is Symbol a text field?  If it isn't, you can't use Like at all since Like implies a text field and you will get incorrect results if you are comparing to a numeric value or date.
Are you really passing a partial string?
Like is very inefficient so you never want to use it unless you actually need it.

If you are using Like because you want the symbol to be optional, then do the following instead:

If Me.Scenario_Code & "" = "" Then
    DoCmd.OpenForm "frm_Legend"
else
    DoCmd.OpenForm "frm_Legend", , , "[Symbol] Like " * "'" & Me.Scenario_Code & "'"
End If

Open in new window

0
 
shieldscoAuthor Commented:
Still get error 13.
I trying to drill down to another form and display the matching value.


Scenario_Code Field                       Symbol Field
CO01.03                                             CO

Compare the first 2 char of the scenario_code field with the Symbol field
0
 
GozrehCommented:
DoCmd.OpenForm "frm_Legend", , , "[Symbol] Like '*" & Me.Scenario_Code & "'"
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
shieldscoAuthor Commented:
The code did not error but it did not find the Symbol code
0
 
GozrehCommented:
Scenario_Code Field                       Symbol Field
CO01.03                                             CO

if this is your example, you need to place the * by the end

DoCmd.OpenForm "frm_Legend", , , "[Symbol] Like '" & Me.Scenario_Code & "*'"
0
 
GozrehCommented:
to make sure,
In your form you have the text CO01.03 and you are placing by the criteria CO
DoCmd.OpenForm "frm_Legend", , , "[Symbol] Like 'CO*'"
0
 
shieldscoAuthor Commented:
How about if we take the left 2 char of the Scenario_Code  field and compare to the 2 digit Symbol field or vice versa??
0
 
GozrehCommented:
so you will need to use the left function
DoCmd.OpenForm "frm_Legend", , , "[Symbol] ='" & Left(Me.Scenario_Code,2) & "'"
0
 
shieldscoAuthor Commented:
Worked Good -- Thanks
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now