My If/Then doesn't fire even though "If" is true

  • Thread starter Thread starter roger
  • Start date Start date
R

roger

I have a column of filepaths and a sub that steps through the table importing
each file. It only works if:
a: There is a filepath stored (and)
b: if there is a file on the HD at that path.

I have two if/then statments designed to trap these conditions

If Me.LibItemFilePath = Null Then GoTo NextRecord 'If no filepath, skip
If Len(Dir(Me.LibItemFilePath)) > 1 Then... 'If file exists
then import

The 1st line fails somehow, and the sub crashes on the 2nd line because the
filepath is null, even though it should never get to the 2nd line if the
filepath is null.

What gives?
 
roger said:
I have a column of filepaths and a sub that steps through the table
importing
each file. It only works if:
a: There is a filepath stored (and)
b: if there is a file on the HD at that path.

I have two if/then statments designed to trap these conditions

If Me.LibItemFilePath = Null Then GoTo NextRecord 'If no filepath,
skip
If Len(Dir(Me.LibItemFilePath)) > 1 Then... 'If file
exists
then import

The 1st line fails somehow, and the sub crashes on the 2nd line because
the
filepath is null, even though it should never get to the 2nd line if the
filepath is null.

What gives?

If Me.LibItemFilePath = Null

should read

If IsNull(Me.LibItemFilePath)

Keith.
www.keithwilby.com
 
roger said:
I have a column of filepaths and a sub that steps through the table
importing
each file. It only works if:
a: There is a filepath stored (and)
b: if there is a file on the HD at that path.

I have two if/then statments designed to trap these conditions

If Me.LibItemFilePath = Null Then GoTo NextRecord 'If no filepath,
skip
If Len(Dir(Me.LibItemFilePath)) > 1 Then... 'If file
exists
then import

The 1st line fails somehow, and the sub crashes on the 2nd line because
the
filepath is null, even though it should never get to the 2nd line if the
filepath is null.

What gives?

In VBA you need to use the IsNull function to check for nulls:

If IsNull(Me.LibItemFilePath) Then
 
Back
Top