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

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?
 
K

Keith Wilby

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
 
S

Stuart McCall

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top