Solved

Dllookup

Posted on 2011-03-06
8
405 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
  • 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 - Access MVP) 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 49

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 49

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

776 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