[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Dllookup

Posted on 2011-03-06
8
Medium Priority
?
439 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 - Microsoft MVP, Access and Data Platform) earned 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 52

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 52

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

872 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