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 - VCat = rsimport("Description")
-
VCategory = DLookup("[Class]", "[Category]", "[Description] = '" & VCat & "'")
-
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.
4 930
Try -
VCategory = DLookup("Class", "Category", "Description = '" & VCat & "'")
-
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
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.
Try Cleaning (removing all non-printable characters) the Excel Data prior to referencing it, as in: - Dim strTest As String
-
-
strTest = vbTab & "Help " & vbCrLf & "me!" & vbCrLf
-
-
Debug.Print "Before Clean: " & strTest
-
Debug.Print "After Clean : " & Application.WorksheetFunction.Clean(strTest)
- Before Clean: Help
-
me!
-
-
After Clean : Help me!
-
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 -
Public Function ELookup(Expr As String, Domain As String, Optional Criteria As Variant, _
-
Optional ORDERClause As Variant) As Variant
-
-
On Error GoTo Err_ELookup
-
'Purpose: Faster and more flexible replacement for DLookup()
-
'Arguments: Same as DLookup, with additional Order By option.
-
'Return: Value of the Expr if found, else Null.
-
' Delimited list for multi-value field.
-
'Author: Allen Browne. allen@allenbrowne.com
-
'Updated: December 2006, to handle multi-value fields (Access 2007.)
-
'Examples:
-
' 1. To find the last value, include DESC in the OrderClause, e.g.:
-
' ELookup("[Surname] & [FirstName]", "tblClient", , "ClientID DESC")
-
' 2. To find the lowest non-null value of a field, use the Criteria, e.g.:
-
' ELookup("ClientID", "tblClient", "Surname Is Not Null" , "Surname")
-
'Note: Requires a reference to the DAO library.
-
Dim MyDb As DAO.Database 'This database.
-
Dim Rs As DAO.Recordset 'To retrieve the value to find.
-
Dim rsMVF As DAO.Recordset 'Child recordset to use for multi-value fields.
-
Dim varResult As Variant 'Return value for function.
-
Dim strSql As String 'SQL statement.
-
Dim strOut As String 'Output string to build up (multi-value field.)
-
Dim lngLen As Long 'Length of string.
-
Const strcSep = "," 'Separator between items in multi-value list.
-
-
'Initialize to null.
-
varResult = Null
-
-
'Build the SQL string.
-
strSql = "SELECT TOP 1 " & Expr & " FROM " & Domain
-
If Not IsMissing(Criteria) Then
-
strSql = strSql & " WHERE " & Criteria
-
End If
-
If Not IsMissing(ORDERClause) Then
-
strSql = strSql & " ORDER BY " & ORDERClause
-
End If
-
strSql = strSql & ";"
-
-
-
Set MyDb = CurrentDb
-
-
Set Rs = MyDb.OpenRecordset(strSql, dbOpenForwardOnly)
-
If Rs.RecordCount > 0 Then
-
'Will be an object if multi-value field.
-
If VarType(Rs(0)) = vbObject Then
-
Set rsMVF = Rs(0).Value
-
Do While Not rsMVF.EOF
-
If Rs(0).Type = 101 Then 'dbAttachment
-
strOut = strOut & rsMVF!FileName & strcSep
-
Else
-
strOut = strOut & rsMVF![Value].Value & strcSep
-
End If
-
rsMVF.MoveNext
-
Loop
-
'Remove trailing separator.
-
lngLen = Len(strOut) - Len(strcSep)
-
If lngLen > 0& Then
-
varResult = Left(strOut, lngLen)
-
End If
-
Set rsMVF = Nothing
-
Else
-
'Not a multi-value field: just return the value.
-
varResult = Rs(0)
-
End If
-
End If
-
Rs.Close
-
-
'Assign the return value.
-
ELookup = varResult
-
-
Exit_ELookup:
-
Set Rs = Nothing
-
Set MyDb = Nothing
-
Exit Function
-
-
Err_ELookup:
-
MsgBox "Error " & Err & " " & Err.Description, vbExclamation, "ELookup Error " & Err.Number
-
Resume Exit_ELookup
-
-
End Function
-
Phil
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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>
|
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...
|
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
|
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...
|
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...
|
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...
|
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.
...
|
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,...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |