Solved

Access 2010 Like Function

Posted on 2014-10-02
9
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 38

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
Industry Leaders: 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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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