Results 1 to 6 of 6
  1. #1
    SHIVA2016 is offline Novice
    Windows 10 Access 2013
    Join Date
    Jan 2016
    Posts
    6

    Dlookup blues


    Hiii to all
    I have problem with dlookup function in vba which is not retrieving records can any one help

    DLookup("[credit]", "datatable", "[mth_year]=#" & MTH & "#" And "[vch_no] = '" & VCHNO & "' And "[alloc] = """8670"""")

    in this mth_year is date field
    vch_no and alloc is string field

    mth_year and vch_no is a criteria and alloc is hard-coded

    thank you
    shiva

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Too many quotes.....

    If [alloc] is a number, try:
    Code:
    DLookup("[credit]", "datatable", "[mth_year]=#" & MTH & "# And [vch_no] = '" & VCHNO & "' And [alloc] = 8670")
    If [alloc] is text, try:
    Code:
    DLookup("[credit]", "datatable", "[mth_year]=#" & MTH & "# And [vch_no] = '" & VCHNO & "' And [alloc] = '8670'")

  3. #3
    SHIVA2016 is offline Novice
    Windows 10 Access 2013
    Join Date
    Jan 2016
    Posts
    6
    alloc is a text

    you guys are great its working thank you

  4. #4
    SHIVA2016 is offline Novice
    Windows 10 Access 2013
    Join Date
    Jan 2016
    Posts
    6
    one more problem, I wan to replace date format in function like

    DLookup("[amount]", "data", "[mth_year] =""" & SQLDate(MTH) & """ And [vch_no] = '" & VCHNO & "' And [alloc] = '003456'")

    sqldate function is

    Function SQLDate(ByRef pvarVdt As Variant) As String
    On Error GoTo Err_SQLDate
    If IsDate(pvarVdt) Then
    SQLDate = "#" & Format$(pvarVdt, "mm/dd/yyyy") & "#"
    End If
    Exit_SQLDate:
    On Error Resume Next
    Exit Function
    Err_SQLDate:
    MsgBox Err.Description, vbCritical, "Module" & ": " & "SQLDate"
    Resume Exit_SQLDate
    End Function


    I getting data type mismatch error
    any help on this

    thank you
    shiva

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Again, too many quotes:

    Try:
    Code:
    DLookup("[amount]", "data", "[mth_year] = " & SQLDate(MTH) & " And [vch_no] = '" & VCHNO & "' And [alloc] = '003456'")
    I did not test this, but try
    Function:
    Code:
    Function SQLDate(ByRef pvarVdt As Variant) As String
        On Error GoTo Err_SQLDate
    
        'default return date so a NULL is not returned
        SQLDate = "#1/1/1900#"
    
        If IsDate(pvarVdt) Then
            SQLDate = "#" & Format(pvarVdt, "mm/dd/yyyy") & "#"
        End If
    
    Exit_SQLDate:
        '    On Error Resume Next
        Exit Function
    Err_SQLDate:
        MsgBox Err.Description, vbCritical, "Module" & ": " & "SQLDate"
        Resume Exit_SQLDate
    
    End Function

  6. #6
    SHIVA2016 is offline Novice
    Windows 10 Access 2013
    Join Date
    Jan 2016
    Posts
    6
    Thanks once again its working

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

Similar Threads

  1. Military Time Blues
    By viperbyte in forum Forms
    Replies: 19
    Last Post: 04-14-2020, 06:45 AM
  2. Parameter Blues..
    By Metrazal in forum Queries
    Replies: 11
    Last Post: 06-10-2014, 12:25 PM
  3. Expression Builder Blues
    By justphilip2003 in forum Forms
    Replies: 8
    Last Post: 05-19-2013, 03:28 PM
  4. Slow Form Blues
    By mickeymatos in forum Forms
    Replies: 2
    Last Post: 12-12-2012, 03:15 PM
  5. Hesitation production psychological SQL Blues
    By byterbit in forum Queries
    Replies: 1
    Last Post: 05-11-2011, 02:36 PM

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