Run time error 13

  • Thread starter Thread starter Simon
  • Start date Start date
S

Simon

I have the flowwong code what works

Private Sub FirstNameSearch_Change()
Me.Requery
Me!FirstNameSearch.SetFocus
Me!FirstNameSearch.SelStart = Len(Me!FirstNameSearch)
End Sub

but if i delete what i tupe in FirstNameSearch Box i get the following
error


Run time error 13
Type Missmatch
END DEBUG


Is there a way how to stop this error
 
The problem is that Len() doesn't like Null.

Try:

Me!FirstNameSearch.SelStart = Len(Me!FirstNameSearch & vbNullString)

or

Me!FirstNameSearch.SelStart = Len(Me!FirstNameSearch & "")
 
Private Sub FirstNameSearch_Change()
On Error Resume Next
Me.Requery
Me!FirstNameSearch.SetFocus
Me!FirstNameSearch.SelStart = Len(Me!FirstNameSearch)
On Error Goto 0
End Sub

Hope this helps?
 
The following should avoid the error:

Me!FirstNameSearch.SelStart = Len(Me!FirstNameSearch & "")

Concatenating the zero-length string onto the control's value means the Len
function is not operating on a Null when you delete the contents of the
control, so will return zero rather than Null.

Ken Sheridan
Stafford, England
 

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

Back
Top