Solved

Dllookup

Posted on 2011-03-06
8
390 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now