field can have 2 different lengths depending on first characters

cjamps

Registered User.
Local time
Today, 18:09
Joined
Feb 2, 2009
Messages
29
if the field starts with "yor" it should allow the user to type 12 characters or else the user should be only able to type 11 characters. How and where do I code this?
 
not easily

in the fields before update event you can check it - it will look something like this. The nz's are necessary as otherwise you may get issues if you delete the contents completely

this is off the top of my head, and not tested

Code:
sub fieldname beforeupdate (cancel as integer) 
dim maxlen as integer

[COLOR="Red"]'assume the length is 11[/COLOR]
maxlen=11

[COLOR="red"]'but its 12 in these circumstances[/COLOR]
if left(nz([fieldname],vbnullstring),3)="yor" then maxlen = 12

[COLOR="red"]'so how long is it?[/COLOR]
if len(nz([fieldname],vbnullstring))>maxlen then
 msgbox("Too long")
[COLOR="red"]'in which case, this prevents the change being accepted[/COLOR]
 cancel = vbcancel
 exit sub
end if
end sub
 
I thought of handling this differently. I am wondering if it is possble to have 2 different inputs masks depending is the field starts with a YO.

Is something like this possible?

IF left(nz([fieldname],vbnullstring),2)="yo"
THEN input mask = "LLL00000-0000"
ELSE
input mask = "LL00000-0000"
ENDIF
 

Users who are viewing this thread

Back
Top Bottom