Results 1 to 3 of 3
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    754

    Function SelectFile Issue

    Hi all,
    My primary form has a image box on it for a logo. My subform has a document management form on it for adding documents which all worked great until


    I added another subform BusinessContacts which also has a image box on it. IN any event, I have spent the better part of this past week trying to fix this as
    I keep getting an error invalid use of null. I do believe the issue is within the added code. See below. I also copied the entire function to below it too for reference.
    Basically, If I am on Primary form, and I select a file for a business Logo, then it stores in a folder attached to where my db is stored. If I select a document then that gets stored in a document folder in the business folder, and If i select a business contact MyPhoto, then it should store in the businesscontact folder and contact id...

    If when i call for one of the DocTypes, it shouldnt want info from a different folder then the one I am looking for but it does. Hope this makes sense.

    I am pretty sure this is the issue but I am not sure how to correct it?
    Code:
        Profile = GetProfile()
        DataFolder = Profile & "\Data"
        BusinessFolder = DataFolder & "\Business"
        BusinessIDFolder = BusinessFolder & "\" & BusinessID
        DocumentFolder = BusinessIDFolder & "\Documents"
    'I added this below
        BusinessContactFolder = BusinessIDFolder & "\BusinessContact"
        BusinessContactIDFolder = BusinessContactFolder & "\" & BusinessContactID
        
        
        ' I believe this is where the issue is in the code........
        CheckFolder Profile
        CheckFolder DataFolder
        CheckFolder BusinessFolder
        CheckFolder BusinessIDFolder
        If Not CheckFolder(DocumentFolder) Then 'Then Exit Sub was origional
    ' I added this below
        ElseIf Not CheckFolder(BusinessContactFolder) Then
        ElseIf Not CheckFolder(BusinessContactIDFolder) Then Exit Sub
        End If
    This is the full function....

    Code:
    Public Function CheckFolder(FolderName) As Boolean
    
    
        Dim FN As String
        
        FN = FolderName
        CheckFolder = True
        If Not FolderExists(FN) Then
            MkDir FolderName
            If Not FolderExists(FN) Then
                MsgBox "ERROR! Could not create " & FN
                CheckFolder = False
            End If
        End If
    
    
    End Function
     
    Public Sub SelectFile(DocType As String)
    
    
        Dim Profile As String
        Dim DataFolder As String
        Dim BusinessFolder As String
        Dim BusinessIDFolder As String
        Dim DocumentFolder As String
        Dim BusinessID As Long
        Dim FD As Office.FileDialog
        Dim PickFile As Variant
        Dim FileName As String, FilePath As String
        Dim NewFilePath As String
        Dim NewFilename As String
    ' I added this below
        Dim BusinessContactFolder As String
        Dim BusinessContactIDFolder As String
        Dim BusinessContactID As Long
        Dim BusinessDocumentID As Long
    
    
        
        
        If IsLoaded("frmBusiness") Then
            BusinessID = Forms!frmBusiness!BusinessID
    
    
        Else
            BusinessID = 0
    
    
        End If
        
        Profile = GetProfile()
        DataFolder = Profile & "\Data"
        BusinessFolder = DataFolder & "\Business"
        BusinessIDFolder = BusinessFolder & "\" & BusinessID
        DocumentFolder = BusinessIDFolder & "\Documents"
    'I added this below
        BusinessContactFolder = BusinessIDFolder & "\BusinessContact"
        BusinessContactIDFolder = BusinessContactFolder & "\" & BusinessContactID
        
        
        
        CheckFolder Profile
        CheckFolder DataFolder
        CheckFolder BusinessFolder
        CheckFolder BusinessIDFolder
        If Not CheckFolder(DocumentFolder) Then 'Then Exit Sub was origional
    ' I added this below
        ElseIf Not CheckFolder(BusinessContactFolder) Then
        ElseIf Not CheckFolder(BusinessContactIDFolder) Then Exit Sub
        End If
        
        Randomize
        Set FD = Application.FileDialog(msoFileDialogFilePicker)
        With FD
            .InitialFileName = Profile
            .AllowMultiSelect = IIf(DocType = "BulkAdd", True, False)
            .Title = "Select a File"
            .Filters.Clear
    'Not sure if I need and AND or and OR between the Business and BusinessContact?"
            If DocType = "Business" Or "BusinessContact" Then
                .Filters.Add "JPG Files", "*.jpg"
                .Filters.Add "GIF Files", "*.gif"
                .Filters.Add "PNG Files", "*.png"
            Else
                .Filters.Add "All Files", "*.*"
            End If
            If .Show = True Then
                For Each PickFile In .SelectedItems
                    FilePath = PickFile
                    FileName = FileNameFromPath(FilePath)
                    NewFilename = Format(Now(), "yymmdd") & "-" & Format(Int(Rnd * 1000), "0000") & "-" & FileName
                    
                    If DocType = "Business" Then
                        Forms!frmBusiness!MyLogo = NewFilename
                        NewFilePath = BusinessIDFolder & "\" & NewFilename
                        
                    ElseIf DocType = "BusinessContact" Then
                        Forms!frmBusiness!sfrmBusinessContact.Form!MyPhoto = NewFilename
                        NewFilePath = BusinessContactIDFolder & "\" & NewFilename
                        
                    ElseIf DocType = "Document" Then
                        Forms!frmBusinessDocument!FileName = NewFilename
                        Forms!frmBusinessDocument!Description = NewFilename
                        NewFilePath = DocumentFolder & "\" & NewFilename
                        Forms!frmBusinessDocument.RefreshDocImage
                        
                    ElseIf DocType = "DocumentSubform" Then
                        Forms!frmBusiness!sfrmBusinessContact.Form!FileName = NewFilename
                        Forms!frmBusiness!sfrmBusinessContact.Form!Description = NewFilename
                        NewFilePath = DocumentFolder & "\" & NewFilename
                        Forms!frmBusiness!sfrmBusinessContact.Form.RefreshDocImage
                        
                    Else ' Bulk Add
                        DoCmd.SetWarnings False
                        DoCmd.RunSQL "INSERT INTO tblBusinessDocument (BusinessID, Filename, Description) " & _
                            "VALUES (" & BusinessID & ", """ & NewFilename & """,""" & NewFilename & """)"
                        DoCmd.SetWarnings True
                        NewFilePath = DocumentFolder & "\" & NewFilename
                    End If
                    FileCopy FilePath, NewFilePath
                    If Not FileExists(NewFilePath) Then
                        MsgBox "ERROR: File Copy Failed. " & NewFilePath
                        Exit Sub
                    End If
                    'Kill FilePath
                    'If FileExists(FilePath) Then
                    '    MsgBox "Could not delete original picture. " & NewFilePath
                    'End If
                Next
            End If
        End With
    
    
    End Sub
    
    
    Public Function FileNameFromPath(FilePath As String) As String
    
    
        FileNameFromPath = Right(FilePath, Len(FilePath) - InStrRev(FilePath, "\"))
    
    
    End Function

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    What line throws error?

    Set a breakpoint and step debug.

    If you want to provide db for analysis, follow instructions at bottom of my post or for more details click the "How to Attach Files" button at top of thread.
    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
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    754
    thanks June7,
    I was able to fix it! Works like a charm now but what an ordeal.... it was
    Thanks
    Dave

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

Similar Threads

  1. Issue with DateAdd function
    By Dave14867 in forum Forms
    Replies: 8
    Last Post: 04-30-2019, 03:35 PM
  2. Syntax issue with Function
    By Cafe2UEMP in forum Programming
    Replies: 5
    Last Post: 12-27-2017, 01:14 PM
  3. DoCmd.TransferText Function issue
    By nick243 in forum Import/Export Data
    Replies: 7
    Last Post: 07-19-2016, 12:00 PM
  4. Aggregation function issue in Access
    By Fais in forum Access
    Replies: 7
    Last Post: 08-06-2014, 04:27 PM
  5. date function return value issue
    By live2ride in forum Access
    Replies: 3
    Last Post: 10-24-2012, 07:06 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