Sarooj
Sarooj

Reputation: 29

Validation Rule in VBA to determine the length of text

I have a form for recording the phone numbers which have two kinds:

I want to make the ValidationRule change according to the Combobox that determines the type of phone numbers.

I tried to use ValidationRule in the form properties but it doesn't work with IIf formula or dependening on the value of another textbox or combobox.

So I made this piece of code, but it doesn't work:

If me.combo.value = "internal" then 
    Me.field.validationrule = "Len([field]) = 4"
ElseIf Me.combo.value = "external" Then 
    Me.field.validationrule = "Len([field]) = 4 or Len([field]) = 7 or Len([field]) = 8"
End If

Thanks in advance.

Upvotes: 0

Views: 500

Answers (2)

Sarooj
Sarooj

Reputation: 29

The code for which I ask

If me.combo.value = "enteral"  then Me.field.validationrule ="Is Null OR Like """"" Elseif me.combo.value = "extetnal" then.   Me.field.validationRule="Is Null OR Like """" OR Like """"  OR Like """""
End if.   

The source https://www.officena.net/ib/topic/87200-التحكم-بخاصية-قاعدة-التحقق-من-الصحة-validationrule-لمربع-نص-برمجياً-vba/

Upvotes: 0

Wolfgang Kais
Wolfgang Kais

Reputation: 4100

You don't have to change the validation rule. Try something like this instead:

([combo]="internal" And Len([field])=4) Or ([combo]="external" And (Len([field])=4 Or Len([field])=7 Len([field])=8))

Upvotes: 1

Related Questions