Solved

Access 2010 Like Function

Posted on 2014-10-02
9
209 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 35

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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

856 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