Results 1 to 4 of 4
  1. #1
    averagejo3 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2018
    Posts
    6

    Run-time error 94: Invalid use of null/ Code has been working for over a month, now I get this error

    In my database I have this simple form:
    Click image for larger version. 

Name:	ImportForm.png 
Views:	16 
Size:	23.9 KB 
ID:	33950
    Its purpose is to import an excel spreadsheet into a specific table in my database. There are two separate ones because the spreadsheets come in two types. So each one accepts a spreadsheet with specific column headers that match the tables they get imported to. This is its underlying vba code:

    Code:
    Option Compare Database
    
    
    Private Sub btnBrowse_Click()
        Dim diag As Office.FileDialog
        Dim item As Variant
        
        Set diag = Application.FileDialog(msoFileDialogFilePicker)
        diag.AllowMultiSelect = False
        diag.Title = "Please select an Excel Spreadsheet"
        diag.Filters.Clear
        diag.Filters.Add "Excel Spreadsheets", "*.xls, *.xlsx"
        
        If diag.Show Then
            For Each item In diag.SelectedItems
                Me.txtFileName = item
            Next
        End If
        
    End Sub
    
    
    Private Sub btnImportSpreadsheet_Click()
        Dim FSO As New FileSystemObject
        
        ' Edit upcoming lines for what table data goes to
        
        If FSO.FileExists(Me.txtFileName) Then
            ExcelImport.ImportExcelSpreadsheet Me.txtFileName, "StuDB_Source"
        Else
            MsgBox "File not found"
        
        End If
        
    End Sub
    
    
    
    
    
    
    Private Sub btnBrowse1_Click()
        Dim diag As Office.FileDialog
        Dim item As Variant
        
        Set diag = Application.FileDialog(msoFileDialogFilePicker)
        diag.AllowMultiSelect = False
        diag.Title = "Please select an Excel Spreadsheet"
        diag.Filters.Clear
        diag.Filters.Add "Excel Spreadsheets", "*.xls, *.xlsx"
        
        If diag.Show Then
            For Each item In diag.SelectedItems
                Me.txtFileName1 = item
            Next
        End If
        
    End Sub
    
    
    Private Sub btnImportSpreadsheet1_Click()
        Dim FSO As New FileSystemObject
        
        ' Edit upcoming lines for what table data goes to
        
        If FSO.FileExists(Me.txtFileName) Then
            ExcelImport.ImportExcelSpreadsheet Me.txtFileName, "Majors_Source"
        Else
            MsgBox "File not found"
        
        End If
        
    End Sub
    This code has been working for me for about a month with no errors, now all of a sudden I get this Invalid use of null error when I try to import on the second import option.


    The first import option still works but whats weird is that now if I import with the first option then try to import with the second option I get this error:
    Click image for larger version. 

Name:	FirstError.png 
Views:	16 
Size:	56.5 KB 
ID:	33951
    So its as if now the second option's code is somehow pulling its source file from the first option, which it has never done before.
    And if I use the second option with the first option I get the invalid use of null:
    Click image for larger version. 

Name:	SecondError.png 
Views:	16 
Size:	53.1 KB 
ID:	33952
    So my thought is that somehow the vba is messed up. If anyone knows how to get around this I would greatly appreciate the help, I'm drawing blank here

  2. #2
    averagejo3 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2018
    Posts
    6
    Also when I run the debug the line that is highlighted is: " If FSO.FileExists(Me.txtFileName) Then" on the lower part of my code

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    Maybe it's the wrong textbox:
    Code:
    Private Sub btnImportSpreadsheet1_Click()
        Dim FSO As New FileSystemObject
        
        ' Edit upcoming lines for what table data goes to
        
        If FSO.FileExists(Me.txtFileName1) Then
            ExcelImport.ImportExcelSpreadsheet Me.txtFileName1, "Majors_Source"
        Else
            MsgBox "File not found"
        
        End If
        
    End Sub

  4. #4
    averagejo3 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2018
    Posts
    6
    Quote Originally Posted by davegri View Post
    Maybe it's the wrong textbox:
    Code:
    Private Sub btnImportSpreadsheet1_Click()
        Dim FSO As New FileSystemObject
        
        ' Edit upcoming lines for what table data goes to
        
        If FSO.FileExists(Me.txtFileName1) Then
            ExcelImport.ImportExcelSpreadsheet Me.txtFileName1, "Majors_Source"
        Else
            MsgBox "File not found"
        
        End If
        
    End Sub
    Wow you are absolutely right, I don't know how I missed that. This is a joint project so somebody else must've messed with the VBA code. Thanks a ton!

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

Similar Threads

  1. Invalid use of Null in Module error
    By Tom123456 in forum Modules
    Replies: 3
    Last Post: 10-13-2017, 07:10 AM
  2. Invalid use of NULL error
    By CHEECO in forum Access
    Replies: 13
    Last Post: 03-16-2016, 07:20 PM
  3. Run time error '94': Invalid Use of Null... help
    By batowl in forum Programming
    Replies: 3
    Last Post: 05-14-2014, 01:58 PM
  4. Replies: 1
    Last Post: 03-22-2013, 09:59 AM
  5. Error 94: Invalid Use of Null
    By athomas8251 in forum Forms
    Replies: 3
    Last Post: 11-09-2011, 11:46 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