Unable to correctly use a module for a file browser

Nevy

Registered User.
Local time
Today, 15:11
Joined
May 31, 2005
Messages
31
Hi, I want to use a module for creating a window file broswer, found here.

It is going to be use to insert an excel file in a table.

The problem is that when I click on cancel, it gives me an error since it doesn't have the string of the filename.

How can I correct that?

At first, this is what I did:
Code:
DoCmd.TransferSpreadsheet acImport, , "MainPrinterTable", GetOpenFile(), True

Then I added this, but still gives me an error.

Code:
Dim strFilePath As String
       
strFilePath = GetOpenFile()
    
If Not IsNull(strFilePath) Then
   DoCmd.TransferSpreadsheet acImport, , "MainPrinterTable", strFilePath, True
End If

The operation of actually importing the file works, it's just the cancel button that isn't.
 
If strFilePath <> ""

IsNull() is looking for a Null

Becareful when looking for Null Variables or just Variables that have empty strings. There came a point when I was regularly checking for Nulls or Empty strings so I just made a different function:

Code:
Public Function IsNullOrEmpty(varValue As Variant) As Boolean
    IsNullOrEmpty = False
    If IsNull(varValue) Or varValue = "" Then
        IsNullOrEmpty = True
        Exit Function
    End If
End Function
 
Last edited:
Thanks. It worked.
 
I think this would also work:
If Len(varValue & "") = 0 then
'-- Nothing in there!
 
Yes it would, but it would also mean that if the string was really long, it would have to get the length of the string, which requires more processing time
 
modest said:
If strFilePath <> ""

IsNull() is looking for a Null

Becareful when looking for Null Variables or just Variables that have empty strings. There came a point when I was regularly checking for Nulls or Empty strings so I just made a different function:

Code:
Public Function IsNullOrEmpty(varValue As Variant) As Boolean
    IsNullOrEmpty = False
    If IsNull(varValue) Or varValue = "" Then
        IsNullOrEmpty = True
        Exit Function
    End If
End Function
modest, I like that. Good idea!

nevy, Why reinvent the wheel? Searching this forum would have led you to this...
Browse [Find a directory or file]
 
When you're really worried about the speed of the program, I wouldn't implement it, but for those times when you're sick of typing it over again and again.. I like to have it
 
Instead of calling a seperate function I'm now using a new method.

Normally I would post this in the Code Repository, but I thought I should post it here since we've been discussing it in this post. It similar to RuralGuy's post, but it doesn't require calling another function, instead it just concatenates and evaluates the expression in the if statement:

Code:
 If varValue & "" = "" Then

This concatenates a "" to the varValue and then evaluates the expression. This is the most resource-efficient way I can think of for completing this. Thank you RuralGuy for your input.
 
You're very welcome. It looks like you have struck on an excellent solution. I didn't realize this was not the OP when I responded the first time.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom