Results 1 to 3 of 3
  1. #1
    RockOnRay is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2013
    Posts
    2

    What am i doing wrong? Dlookup

    This is the scenario of what i am trying to do with the database i am working on .

    1. The user tries to import a file by pressing a command button.



    2. The VBA code behind the button checks the "last modified" date of the file against a stored "last modified" date associated with that file. This stored date is in a table that lists the files and their most recent "modified" dates. If the file is newer, the file is imported. If the file is NOT newer, the user is informed that the current data is up to date.
    If the file is newer:
    3. The file's "last modified" is stored in a table.
    4. The file data is imported.

    What i have as of now is not working. When its performing a dlookup its giving me a runtime error 94 which is Invalid Use Of Null. I will post the code here and if anyone could help me out i would appreciate it. If you have any question please let me know. I will respond asap.

    Code:
    Private Sub ImportBtn_Click()
    
        Dim iFile1 As Date
        Dim iFile2 As Date
        Dim iFile3 As Date
        Dim iFile4 As Date
        Dim File1 As String
        Dim File2 As String
        Dim File3 As String
        Dim File4 As String
        'Dim strJobID As String
        
        DoCmd.SetWarnings False
        
        File1 = DateValue(GetFileDateTime("F:\ProsData\Warehouse\Databases\Rayhan\Projects\Excel\david\Permit 50 Pre Sort.xls"))
        File2 = DateValue(GetFileDateTime("F:\ProsData\Warehouse\Databases\Rayhan\Projects\Excel\david\Pre Sort ML.xls"))
        File3 = DateValue(GetFileDateTime("F:\ProsData\Warehouse\Databases\Rayhan\Projects\Excel\david\Pre Sort.xls"))
        File4 = DateValue(GetFileDateTime("F:\ProsData\Warehouse\Databases\Rayhan\Projects\Excel\david\WonW Pre Sort.xls"))
        
        'strJobID = DLookup("[JobTypeID]", "Q_xLDateQuery", "[Date Field] =' JobTypeID'")
        
        'If Not IsNull(DLookup("[Date Field]", "Q_xLDateQuery", "[Date Field] = #" & File1 & "# And [Job Type ID] = '" & strCarrier & "'")) Then
        
       ' Else
       'End If
        
        iFile1 = DLookup("[Date Field]", "Q_xLDateQuery", "[Date Field] =  #" & File1 & "#")
        iFile2 = DLookup("[Date Field]", "Q_xLDateQuery", "[Date Field] =  #" & File2 & "#")
        iFile3 = DLookup("[Date Field]", "Q_xLDateQuery", "[Date Field] =  #" & File3 & "#")
        iFile4 = DLookup("[Date Field]", "Q_xLDateQuery", "[Date Field] =  #" & File4 & "#")
        '____________________________________________________________________________
        If Not IsNull(iFile1) Then
            MsgBox "You have already transfered Permit 50 Pre Sort Excel File.", vbOKOnly
            
        Else
            DoCmd.RunMacro "Import_Permit50"
        End If
        '_____________________________________________________________________________
        If IsNull(iFile2) = False Then
            MsgBox "You have already transfered Pre Sort ML Excel File.", vbOKOnly
            
        Else
            DoCmd.RunMacro "Import_PreSortML"
        
        End If
        '_____________________________________________________________________________
            
        If IsNull(iFile3) = False Then
           MsgBox "You have already transfered Pre Sort Excel File.", vbOKOnly
        
        Else
            DoCmd.RunMacro "Import_PreSort"
        End If
        '______________________________________________________________________________
        
        If IsNull(iFile4) = False Then
            MsgBox "You have already transfered WonW Pre Sort Excel File.", vbOKOnly
        Else
                
            DoCmd.RunMacro "Import_WonW"
        End If
        '______________________________________________________________________________
    DoCmd.OpenQuery "Apnd_XLerror"
    
    
    DoCmd.SetWarnings True
    
    
        MsgBox "All the Excel Reports has been transfered", vbOKOnly
    
    -----------------------------------------------------------------------------------------
    Public Function GetFileDateTime(sFilePathAndName As String)
    On Error GoTo Error_Handler
    
    
        GetFileDateTime = FileDateTime(sFilePathAndName)
    
    
    Error_Handler_Exit:
        On Error Resume Next
        Exit Function
    
    
    Error_Handler:
        MsgBox "The following error has occured." & vbCrLf & vbCrLf & _
                "Error Number: " & Err.Number & vbCrLf & _
                "Error Source: GetFileDateTime" & vbCrLf & _
                "Error Description: " & Err.Description, _
                vbCritical, "An Error has Occured!"
        Resume Error_Handler_Exit
    
    
    End Function
    End Sub


  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, a variable declared as Date can't take a Null, which is likely why you get an error. You're testing for Null later, so is it possible for the DLookup to return Null? If so, you want to change the data type of the variables to Variant.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

    In the code you posted, the last two lines are
    Code:
    End Function 
    End Sub
    You cannot have a Function nested inside a Sub.

    Move the "End Sub" above
    "Public Function GetFileDateTime(sFilePathAndName As String)"



    I think there better methods the compare the dates.
    One way might be (still not very good), is to wrap the DLookup in the NZ() function, then compare if iFile > File1

    (UNTESTED - Air code)
    Code:
        iFile1 = Nz(DLookup("[Date Field]", "Q_xLDateQuery", "[Date Field] =  #" & File1 & "#"), #1/1/1900#)
        '____________________________________________________________________________
        If Not iFile1 > File1 Then
            MsgBox "You have already transfered Permit 50 Pre Sort Excel File.", vbOKOnly
            
        Else
            DoCmd.RunMacro "Import_Permit50"
        End If

    I just don't like using the DLookup() function for this..

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

Similar Threads

  1. Wrong path
    By djb1011 in forum Queries
    Replies: 1
    Last Post: 02-23-2013, 12:21 AM
  2. What is wrong with my DLookup?
    By BRV in forum Programming
    Replies: 8
    Last Post: 11-03-2011, 01:21 PM
  3. What's wrong!
    By khalid in forum Programming
    Replies: 15
    Last Post: 06-27-2011, 06:38 AM
  4. What is wrong with this IFF?
    By bburton in forum Reports
    Replies: 2
    Last Post: 03-16-2011, 10:42 AM
  5. What am I doing wrong?
    By brandon in forum Access
    Replies: 2
    Last Post: 08-03-2008, 10:26 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