Solved

Access 2010 Like Function

Posted on 2014-10-02
9
212 Views
Last Modified: 2014-10-02
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
Comment
Question by:shieldsco
  • 4
  • 4
9 Comments
 
LVL 36

Expert Comment

by:PatHartman
ID: 40357937
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
 

Author Comment

by:shieldsco
ID: 40357982
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
 
LVL 10

Expert Comment

by:Gozreh
ID: 40358001
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!

 

Author Comment

by:shieldsco
ID: 40358040
The code did not error but it did not find the Symbol code
0
 
LVL 10

Expert Comment

by:Gozreh
ID: 40358048
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
 
LVL 10

Expert Comment

by:Gozreh
ID: 40358060
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
 

Author Comment

by:shieldsco
ID: 40358083
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
 
LVL 10

Accepted Solution

by:
Gozreh earned 500 total points
ID: 40358096
so you will need to use the left function
DoCmd.OpenForm "frm_Legend", , , "[Symbol] ='" & Left(Me.Scenario_Code,2) & "'"
0
 

Author Closing Comment

by:shieldsco
ID: 40358116
Worked Good -- Thanks
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question