Results 1 to 9 of 9
  1. #1
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172

    DLookup with Text

    Hi,

    I'm trying to use the DLookup function, and the quotes around the text are driving me crazy, I just can't get it right. If anyone could help I'd really appreciate it. What I have so far is:

    If IsNull(DLookup("[Total]", "qryMyQueryName", "[Name]=" ""FirstName & ' ' & LastName"" And [Total]<>)")) Then

    Me.MyGraph.ChartTitle.Text = "My Report Name - No Data to Display"
    Else
    Me.MyGraph.ChartTitle.Text = "My Report Name"


    End If

    It's failing at the DLookup, and I know my syntax is wrong - any suggestions?

    Kirsti

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I find it easier to use apostrophes for text delimiters. Otherwise, must triple the quote marks. FirstName and LastName are fields of form RecordSource? I assume you want <>0. Designate empty string with quote marks. Also need concatenation of FirstName. Also assume [Name] field is a constructed field in query that concatenates FirstName and Lastname. Why do search on name and not a unique id? What if you have two John Smith?

    IsNull(DLookup("[Total]", "qryMyQueryName", "[Name]='" & Me!FirstName & " " & Me!LastName & "' And [Total]<>0))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    In plain English what is the DLookup criteria ?

    What is in the Name field in your table?

    OOops I see June7 posted while I was typing.

  4. #4
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Hi June, sorry, I will go with Orange's advice and explain in plain english, as FirstName and LastName are not actually fields.
    And now that I think about this, perhaps DLookup is not the way to go at all.

    I want the IfThenElse of the report name to be based on a qryMyQuery, where the [Total] field <>0 And the [Name] field is a particular persons name (I know that it isn't good practice to hard code a name, but there are only 4 names it could possibly be).

    Does that make things any clearer?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    You want to hard code an actual name, not variables, into the DLookup?

    IsNull(DLookup("[Total]", "qryMyQueryName", "[Name]='John Smith' And [Total]<>0))

    Do you have this code in the report Detail format event?

    Is the condition backwards? Should it be =0 so title will be 'No Data'?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Hi June, yes that's right (I want to hard code a name, and it is in the report Detail format event.

    I tried your code, but got "Run-time error '2001': You cancelled the previous operation" when I tried to open the report.

    My exact code is:

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If IsNull(DLookup("[Total]", "qryTTRS2_YTD8", "[Housing_Officer_Name]='Andrea Goodman' And [Total]<>0")) Then
    Me.Graph25.ChartTitle.Text = "Reason Tenants are Vacating YTD - No Data to Display"
    Else
    Me.Graph25.ChartTitle.Text = "Reason Tenants are Vacating YTD"
    End If
    End Sub

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Chart is also in the Detail section of report? I don't know why code would fail unless it is because chart has no data. I do something very similar to set axis titles and never encountered this error.

    An alternative would be to not display the chart title but to use a label and code to set caption.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Yes, it's strange. I have exactly the same code working for a number of reports, however without the hard coded name in the DLookup, so I assumed it was something to do with the syntax. I'll keep looking - thanks for your help.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I do something similar but not with a hard-coded value. However, I don't see why that would make a difference from using a variable.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-24-2012, 04:59 AM
  2. Replies: 2
    Last Post: 03-01-2012, 12:21 PM
  3. DLookup() for Text Box Control Source
    By tylerg11 in forum Forms
    Replies: 3
    Last Post: 02-06-2012, 02:21 PM
  4. Replies: 15
    Last Post: 04-01-2011, 11:41 AM
  5. Using Dlookup in unbound text box in report
    By PrintShopSup in forum Reports
    Replies: 3
    Last Post: 12-27-2010, 10:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums