Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation question

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How do you make this statement work? I need it to check for double quotes, but the single quotes aren't cutting it.

For index = 1 To Len(txtDescription.Text)
If Mid(txtDescription.Text, index) = "''" Then
Call MsgBox("Description may not contain double quotes.", vbOKOnly + vbInformation)
Call txtDescription.SetFocus
Exit Sub
End If
Next index
 
Try using the Chr function:

For index = 1 To Len(txtDescription.Text)
If Mid(txtDescription.Text, index) = Chr(34) Then
Call MsgBox("Description may not contain double quotes.", vbOKOnly + vbInformation)
Call txtDescription.SetFocus
Exit Sub
End If
Next index

Also, if you just want ot see if a string contains a character (double quote in this case), try using the InStr command:

If InStr(txtDescription.Text, Chr(34)) > 0 Then ' double quote found
Call MsgBox("Description may not contain double quotes.", vbOKOnly + vbInformation)
End If


Simon
 
Try checking for the ascii number for the double quote instead.
 
Dont even bother the user of the ap with error messages just fix the problem for them.

Replace the double quotes with the character with the ascii number of 96 it also helps if you need to insert the record into a database !


if instr(description,chr(34)) then
replace(desription,chr(34),"`")
end if

-tryp
 
Or add another so that when it is saved the double quote remains in the string and no error are received.

EG if you had the string abcd"efgh, change this to abcd""efgh.

Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top