Results 1 to 7 of 7
  1. #1
    irenef1223 is offline Novice
    Windows 10 Office 365
    Join Date
    Aug 2021
    Posts
    4

    DLookup Function

    Hello! I need some help on the DLookup function in access. I have a form with an unbound textbox and a button, and what I want the button to do is, based on the number of days entered in the unbound textbox, open a form that will allow me to send emails to recipients based on the notification dates in my extension table. Below is the code I'm using; however, when I enter the number of days I only receive the message that I do not have notices to send, but there are notices that need to be sent, so my code isn't looking up the dates correctly. The criteria in my query for each of the notification dates is <(Date()+[Forms]![EXT NOTICE]![txtNotify])

    Button Event Procedure:

    Private Sub Command2_Click()
    Dim db As DAO.Database, rst As DAO.Recordset
    If IsNull(DLookup("[EXT NOTIFY DATE 1] &','& [EXT NOTIFY DATE 2] &','& [EXT NOTIFY DATE 3] &','& [EXT NOTIFY DATE 4]", "[EXT TBL]")) Then
    MsgBox "There are no extension notices to send."
    DoCmd.Close acForm, Me.Name
    DoCmd.OpenForm "MAIN MENU", acNormal, "", "", acAdd, acNormal
    Else
    ' Point to this database
    Set db = CurrentDb
    ' Clean out the working table
    CurrentDb.Execute "DELETE * FROM [EXT TBL]", dbFailOnError
    ' Avoid prompts
    DoCmd.SetWarnings False
    ' Load in the rows to select
    DoCmd.OpenQuery "EXT NOTICE Query"
    ' Turn on prompts again
    DoCmd.SetWarnings True
    ' Clear the database object
    Set db = Nothing
    ' Open the selection form
    DoCmd.OpenForm "EXT SEND FRM"
    ' Close me
    DoCmd.Close acForm, Me.Name
    End If
    End Sub




    Any help is greatly appreciated!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    sWhereClause = "[name]='Bob'"

    =Dlookup("[Field2Return]", "qryOrTbl",sWhereClause)

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,997
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    irenef1223 is offline Novice
    Windows 10 Office 365
    Join Date
    Aug 2021
    Posts
    4
    Isn't anyone kind or understanding anymore? I thought this was a forum where you could come and get help, or am I wrong? I DID Google, and none of the sites, including the one you provided, helped me with my issue. I'll try to find another site where perhaps people are more willing to help than put others down or make them feel dumb for asking for help. Have a great day!

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,421
    The DLookup worked for me, but you're clearing your table before running the query, so nothing will ever be found.
    You don't need to dim the db or the rst, as they aren't used.

    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub Command2_Click()
        If IsNull(DLookup("[EXT NOTIFY DATE 1] &','& [EXT NOTIFY DATE 2] &','& [EXT NOTIFY DATE 3] &','& [EXT NOTIFY DATE 4]", "[EXT TBL]")) Then
            MsgBox "There are no extension notices to send."
            DoCmd.Close acForm, Me.Name
            DoCmd.OpenForm "MAIN MENU", acNormal, "", "", acAdd, acNormal
            DoCmd.Close acForm, Me.Name
            Exit Sub
        End If
    
    
        ' Clean out the working table
        CurrentDb.Execute "DELETE * FROM [EXT TBL]", dbFailOnError  '<<<<<<<<<<<<<<<<
        ' Avoid prompts
        DoCmd.SetWarnings False
        ' Load in the rows to select
        DoCmd.OpenQuery "EXT NOTICE Query"            '<<<<<  looks at table [EXT TBL] ?  It's empty!
        ' Turn on prompts again
        DoCmd.SetWarnings True
        ' Open the selection form
        DoCmd.OpenForm "EXT SEND FRM"
        ' Close me
        DoCmd.Close acForm, Me.Name
    End Sub
    Last edited by davegri; 09-14-2022 at 12:48 PM. Reason: addl clarif

  6. #6
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,570
    Hi

    This looks like your tables are not normalised:-

    [EXT NOTIFY DATE 1] &','& [EXT NOTIFY DATE 2] &','& [EXT NOTIFY DATE 3] &','& [EXT NOTIFY DATE 4]

    Can you upload a copy of your database with some random unclassified data?



    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,997
    Quote Originally Posted by irenef1223 View Post
    Isn't anyone kind or understanding anymore? I thought this was a forum where you could come and get help, or am I wrong? I DID Google, and none of the sites, including the one you provided, helped me with my issue. I'll try to find another site where perhaps people are more willing to help than put others down or make them feel dumb for asking for help. Have a great day!
    Don't throw your toys out of the pram?
    A simple google would give you the syntax for a dlookup, then you just need to get the criteria correct.
    I tend to put the criteria into a string variable, so I can debug.print it until I get it correct. Then I can use that string variable in the domain function?
    You appear to want to retrieve 4 fields, which are numerically suffixed, which gives the impression your structure is incorrect?
    TBH I cannot see how you would get null, when you concatenate , between the field values?
    You also appear to be using a very advanced method of dlookup, that is rarely seen?
    Perhaps explain in plain words how all these dates work together, plus how the queries for each date come into it?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. DLookup function - need help
    By Lukael in forum Programming
    Replies: 4
    Last Post: 03-13-2016, 05:34 AM
  2. Dlookup Function
    By balajigade in forum Access
    Replies: 2
    Last Post: 09-10-2015, 01:55 AM
  3. DLookup Function
    By Alex Motilal in forum Programming
    Replies: 8
    Last Post: 08-14-2014, 01:15 PM
  4. DLOOKUP function
    By tariq1 in forum Programming
    Replies: 5
    Last Post: 07-17-2012, 04:22 PM
  5. Need Help for Dlookup function
    By wasim_sono in forum Programming
    Replies: 5
    Last Post: 01-04-2006, 08:18 AM

Tags for this Thread

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