473,396 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can not get a match on a string

489 256MB
This is driving me crazy, I have an excel file that I load into a table. In this table there is a description of a category EX: "B Western" I have a table in my data base (Category) that has the description with B Western in it and also a class BW. I want to find this class so I do a dlookup to find the class, it looks like the description matches but it will not give me the class it comes up with a null
Expand|Select|Wrap|Line Numbers
  1.         VCat = rsimport("Description")
  2.         VCategory = DLookup("[Class]", "[Category]", "[Description] = '" & VCat & "'")
  3.  
is there something when I load the excel file that I don't see that could be causing this not to be found?
I've tried everything even using a Like instead of a = and have put * after the B Western but still get a null if I put a * in from and behind I do get a class code but because there is a B Western with the work Ladies in front it picks that one up. So it looks like there might be something in front of the B Western that I don't see. The excel field is formatted as a text field and when I changed it to general I get the same thing. I know that excel has a code that is put in from of the field for justification of the field and if that's the case how do I do away with that code.
Again any help is greatly appreciated.
Nov 22 '16 #1
4 930
PhilOfWalton
1,430 Expert 1GB
Try

Expand|Select|Wrap|Line Numbers
  1.  VCategory = DLookup("Class", "Category", "Description = '" & VCat & "'")
  2.  
Your problem is for example that your original "[Category]" is looking for a table named [Category] including the square brackets.

Your table name is simply Category.

Phil
Nov 22 '16 #2
CD Tom
489 256MB
That's not the answer I use brackets in all my Dlookup and have no problem, I did try it without the brackets and get the same answer.
Nov 23 '16 #3
ADezii
8,834 Expert 8TB
Try Cleaning (removing all non-printable characters) the Excel Data prior to referencing it, as in:
Expand|Select|Wrap|Line Numbers
  1. Dim strTest As String
  2.  
  3. strTest = vbTab & "Help " & vbCrLf & "me!" & vbCrLf
  4.  
  5. Debug.Print "Before Clean: " & strTest
  6. Debug.Print "After Clean : " & Application.WorksheetFunction.Clean(strTest)
Expand|Select|Wrap|Line Numbers
  1. Before Clean:   Help 
  2. me!
  3.  
  4. After Clean : Help me!
  5.  
Nov 23 '16 #4
PhilOfWalton
1,430 Expert 1GB
I apologise, I didn't know you could use square brackets.

This function is essentially the same as DLookup, but will allow you to step through the code and see what is happening.
Just change DLookup to ELookup

I suspect that your VCat is dodgy for some reason.

Feed in your in

Expand|Select|Wrap|Line Numbers
  1. Public Function ELookup(Expr As String, Domain As String, Optional Criteria As Variant, _
  2.     Optional ORDERClause As Variant) As Variant
  3.  
  4.     On Error GoTo Err_ELookup
  5.     'Purpose:   Faster and more flexible replacement for DLookup()
  6.     'Arguments: Same as DLookup, with additional Order By option.
  7.     'Return:    Value of the Expr if found, else Null.
  8.     '           Delimited list for multi-value field.
  9.     'Author:    Allen Browne. allen@allenbrowne.com
  10.     'Updated:   December 2006, to handle multi-value fields (Access 2007.)
  11.     'Examples:
  12.     '           1. To find the last value, include DESC in the OrderClause, e.g.:
  13.     '               ELookup("[Surname] & [FirstName]", "tblClient", , "ClientID DESC")
  14.     '           2. To find the lowest non-null value of a field, use the Criteria, e.g.:
  15.     '               ELookup("ClientID", "tblClient", "Surname Is Not Null" , "Surname")
  16.     'Note:      Requires a reference to the DAO library.
  17.     Dim MyDb As DAO.Database          'This database.
  18.     Dim Rs As DAO.Recordset         'To retrieve the value to find.
  19.     Dim rsMVF As DAO.Recordset      'Child recordset to use for multi-value fields.
  20.     Dim varResult As Variant        'Return value for function.
  21.     Dim strSql As String            'SQL statement.
  22.     Dim strOut As String            'Output string to build up (multi-value field.)
  23.     Dim lngLen As Long              'Length of string.
  24.     Const strcSep = ","             'Separator between items in multi-value list.
  25.  
  26.     'Initialize to null.
  27.     varResult = Null
  28.  
  29.     'Build the SQL string.
  30.     strSql = "SELECT TOP 1 " & Expr & " FROM " & Domain
  31.     If Not IsMissing(Criteria) Then
  32.         strSql = strSql & " WHERE " & Criteria
  33.     End If
  34.     If Not IsMissing(ORDERClause) Then
  35.         strSql = strSql & " ORDER BY " & ORDERClause
  36.     End If
  37.     strSql = strSql & ";"
  38.  
  39.  
  40.     Set MyDb = CurrentDb
  41.  
  42.     Set Rs = MyDb.OpenRecordset(strSql, dbOpenForwardOnly)
  43.     If Rs.RecordCount > 0 Then
  44.         'Will be an object if multi-value field.
  45.         If VarType(Rs(0)) = vbObject Then
  46.             Set rsMVF = Rs(0).Value
  47.             Do While Not rsMVF.EOF
  48.                 If Rs(0).Type = 101 Then        'dbAttachment
  49.                     strOut = strOut & rsMVF!FileName & strcSep
  50.                 Else
  51.                     strOut = strOut & rsMVF![Value].Value & strcSep
  52.                 End If
  53.                 rsMVF.MoveNext
  54.             Loop
  55.             'Remove trailing separator.
  56.             lngLen = Len(strOut) - Len(strcSep)
  57.             If lngLen > 0& Then
  58.                 varResult = Left(strOut, lngLen)
  59.             End If
  60.             Set rsMVF = Nothing
  61.         Else
  62.             'Not a multi-value field: just return the value.
  63.             varResult = Rs(0)
  64.         End If
  65.     End If
  66.     Rs.Close
  67.  
  68.     'Assign the return value.
  69.     ELookup = varResult
  70.  
  71. Exit_ELookup:
  72.     Set Rs = Nothing
  73.     Set MyDb = Nothing
  74.     Exit Function
  75.  
  76. Err_ELookup:
  77.     MsgBox "Error " & Err & " " & Err.Description, vbExclamation, "ELookup Error " & Err.Number
  78.     Resume Exit_ELookup
  79.  
  80. End Function
  81.  
Phil
Nov 23 '16 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tom Warren | last post by:
I found a c program called similcmp on the net and converted it to vba if anybody wants it. I'll post the technical research on it if there is any call for it. It looks like it could be a useful...
0
by: Lee Kuhn | last post by:
Is there a way to add a literal character to a regex match? For example, normally applying the regex ..$ to the string "123456" results in a match "56". I want to be to add a literal character to...
5
by: Jay S | last post by:
Hi, Can't figure out the following: <concept> I want to match a specified string followed by any string that is *not* a different specified string. </concept> <specific example>
1
by: varunhome | last post by:
Hi, I want to check for the absence of a string in regular expression. For example, if the string is "Error opening file: Permission denied. Aborting.", I want to check for absence of the string...
4
by: somebody | last post by:
If I have an array like: @arr = ('one', 'two', 'three'); And the varaible $myvar = 'two'; How do I check if $myvar matches 'two' in @arr? I know I could iterate through the array with
1
by: justin.mayes | last post by:
hello all - An example. You have a regular expression to locate certain html tags. "(<)" This will find every instance of a "<" character that is not followed by a letter. The match will...
4
by: gfrith | last post by:
Hi, A quick regex question which I've worked around for the time being, but would like an answer to if anyone can help. I want to match on all strings which end _id, but not those ending...
11
by: Flyzone | last post by:
Hello, i have again problem with regexp :-P I need to match all lines that contain one word but not contain another. Like to do "grep one | grep -v two:" The syntax of the string is: (any...
0
by: Travis Kirstine | last post by:
I am new to python and could use some help with a fairly easy task. I would like to return all lines in a file that have the string '<coordinates>' to a list. Regards, -- Travis K. ...
0
by: Chris Rebert | last post by:
On Tue, Oct 28, 2008 at 11:37 AM, Travis Kirstine <traviskirstine@gmail.comwrote: from __future__ import with_statement with open('path/to/file') as f: desired_lines = For your reference,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.