On the form, I have an editable text field, TestimonialText, where the text in the field must be enclosed in quotes. In the QuerySave event, I added the following code to validate the TestimonialText field. When I entered a text without any quote, I get the error message as expected, but if I enter only one double quote instead of 2, I don’t get the error message. Does anyone have any suggestions? Thanks for your help in advanced!
pos = Instr(strTestimonialText, |"|)
If pos < 1 Then
Messagebox “The text of the testimonial must be enclosed in double quotes.” ,0+16, “Testimonial Text Error”
Call source.GotoField(“TestimonialText”)
Continue = False
Exit Sub
End If
Subject: RE: Validating Text Using Instr
My suggestion is, don’t make your users jump through hoops. If there always have to be quotes around the text, put them on the form, don’t force people to do the extra work of typing them into the field. Who is the master here, the person or the machine?
Subject: RE: Validating Text Using Instr
Thank you Andre for your response. How would you suggest I do that? I added code in InputTranslation but every time I exit the field, it keeps adding quotes rather than only add them once. Below is the code I used in the field’s InputTranslation:
{“} + TestimonialText + {”}
Subject: RE: Validating Text Using Instr
You need a condition to add them only if they don’t exist:
@if(@left(TestimonialText; 1) = {“} & @right(TestimonialText; 1) = {”}; TestimonialText; {“} + TestimonialText + {”})
Subject: RE: Validating Text Using Instr
{“} + @replacesubstring(TestimonialText; “"”; “”) + {”}
U can use this if you are sure that there will be no quotes within the string
Subject: RE: Validating Text Using Instr
Thank you, Mary Anne. Your suggestion worked perfectly.
Subject: RE: Validating Text Using Instr
Though Mary Anne’s code will work, it only checks for BOTH of the quotes. You may want to go one step further and check both beginning and end quotes separately…in the event the user only enters one set of quotes.
Subject: RE: Validating Text Using Instr
Very true - and users are known for breaking things in a variety of ways (like only entering one quote).
Subject: A method to check each quote individually
@if(@left(TestimonialText; 1) = {“}; “”; {”}) + TestimonitalText + @if(@right(TestimonialText; 1) = {“}; “”; {”})
Subject: RE: A method to check each quote individually
Thank you, Mary Anne. It worked perfectly.