Solved

Dllookup

Posted on 2011-03-06
8
425 Views
Last Modified: 2012-05-11
I am struggling with the syntax for a Dlookup in the where section

Dim SC As Long
Dim MaxLD As Date
MaxLD = DMax("qry_SecurityCheck.[LoginDate]", "qry_SecurityCheck")
SC = DLookup("[SecurityLevel]", "qry_SecurityCheck", "qry_SecurityCheck.[LoginDate]='" & MaxLD & "'")

I keeping getting expression mismatch errors or syntax errors as i play withe format
MaxLD is date-time format.

Any help welcome, thanks
0
Comment
Question by:SweetingA
[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
  • 2
  • 2
8 Comments
 
LVL 75
ID: 35046995
Assuming LoginDate is a Date (?) ... try this

Dim SC As Date  ' change this is you are returning a Date ..?
Dim MaxLD As Date
MaxLD = DMax("qry_SecurityCheck.[LoginDate]", "qry_SecurityCheck")

SC = DLookup("[SecurityLevel]", "qry_SecurityCheck", "[LoginDate]= #" & MaxLD & "#")

mx
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 total points
ID: 35047051
Please indicate the data type for LoginDate (Date)..  and SecurityLevel (Long ?)

Try this mod .....

Dim SC As LONG ' I put this back to Long ...
Dim MaxLD As Date
MaxLD = DMax("[LoginDate]", "qry_SecurityCheck")

SC = DLookup("[SecurityLevel]", "qry_SecurityCheck", "[LoginDate]= #" & MaxLD & "#")

mx
0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 35047115
Try setting a String variable for use as the filter.  This allows you to check that it has appropriate values, by displaying it in the Immediate window.
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 50

Expert Comment

by:Gustav Brock
ID: 35060698
You need to format a string expression of your MaxLD:

Dim SC As Long
Dim MaxLD As Date
Dim strMaxLD As String
MaxLD = DMax("qry_SecurityCheck.[LoginDate]", "qry_SecurityCheck")
strMaxLD = Format(MaxLD, "yyyy\mm\dd")
SC = DLookup("[SecurityLevel]", "qry_SecurityCheck", "qry_SecurityCheck.[LoginDate]=#" & strMaxLD & "#")

/gustav
0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 35061540
If LoginDate is a Date field, then filtering it with a String variable is problematic.  You should use a Date variable for this purpose.
0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 35061564
Here is a typical SQL string using a Date variable:
strSQL = "SELECT * FROM " & strRecordSource & " WHERE " _
   & "[dteDateReceived] Between " & Chr(35) & dteFromDate _
   & Chr(35) & " And " & Chr(35) & dteToDate & Chr(35) & ";"

Open in new window

0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 35061577
Chr(35) is the same as the # sign.
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 35061706
Helen, that won't work.

Criteria in the domain functions must be string expressions. If not, the value will be casted to a string anyway but outside your control - a date/time value will be casted using the current locale which - as this is in Central Europe - most likely will be dd-mm-yyyy. As the domain functions expect the mm/dd/yyyy format, month and date will be interchanged for values of 12 or less causing errors.

The ISO format yyyy-mm-dd is accepted as well, and as this in mandatory for ADO and preferred for SQL Server, you can just as well make turn it into a habit to format date/time string expressions to the ISO format.

/gustav
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

729 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