Solved

Dllookup

Posted on 2011-03-06
8
426 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 51

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 51

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

624 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