Home > Enterprise >  Why when textbox is null and Len & Dir called causing Error: 13 Type Mismatch
Why when textbox is null and Len & Dir called causing Error: 13 Type Mismatch

Time:11-19

Every time the below code is ran Error Code: 13 Type Mismatch is reported.

If Not Len(Dir(Me.ImageURL)) = 0 Then
   Application.FollowHyperlink (Me.ImageURL)
End If

This only occurs when Me.ImageURL is equal to Null. Thus I attempted the following with no success.

If Not Len(Dir(Me.ImageURL)) = 0 And Not Nz(Me.ImageURL, "") = "" Then
    Application.FollowHyperlink (Me.ImageURL)
End If

CodePudding user response:

Forget the If statements. Just use the Nz function.

Application.FollowHyperlink Nz(Me.ImageURL, "")

Your particular problem, if you want to know, is Dir(Me.ImageURL). I'm guessing Dir can't handle a Null value.

  •  Tags:  
  • vba
  • Related