user1433308
user1433308

Reputation: 1

Need alternative to Not IsEmpty() in VBA

I want to check whether two textboxes have text in them. If they both do, I want to replace box 1 with box 2. This is VBA I'm using If Not IsEmpty(txtBox1) and Not isEmpty(txtBox2) then

but it's not going into the code. I'd rather not use two negatives in an And statement. What else is there?

The rest of the code is working.

Upvotes: 0

Views: 1136

Answers (1)

xxbbcc
xxbbcc

Reputation: 17327

Use

If Len(txtbox1)>0 And Len(txtbox2)>0 Then
    'Do something
End If

The IsEmpty() function is not for checking strings - it's for checking if a Variant has been set to a value or not; uninitialized variants are empty but a variant with a value is not. A valid string is not Empty.

Upvotes: 3

Related Questions