?
Solved

InStr Function (Single and Double Quotes)

Posted on 2003-03-22
10
Medium Priority
?
478 Views
Last Modified: 2008-02-01
This is what I'm using to check for the charactor ( - ). I need code to check for all the following charactors: Single Quote ' and Double Quote " and the dash - . Could someone help?

Check4Charactor = Trim$(Me.textBoxes(2).Text)

MyPos = InStr(1, Check4Charactor, "-")

If MyPos = True Then
 MsgBox "Avoid using ' - ' in your user name."
 Me.textBoxes(2).SetFocus
Exit Sub
End If

Thanks - ADawn
0
Comment
Question by:ADawn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 39

Expert Comment

by:appari
ID: 8186394
try
MyPos = InStr(1, Check4Charactor, "-") or InStr(1, Check4Charactor, "'") or InStr(1, Check4Charactor, """")

to check if atleast oneof the characters exists and if want to check for existance of all the characters use

MyPos = InStr(1, Check4Charactor, "-") and InStr(1, Check4Charactor, "'") and InStr(1, Check4Charactor, """")
0
 
LVL 34

Expert Comment

by:arbert
ID: 8187005
Why don't you code something in the key_down event that checks for those characters and warn them right when they enter the character.....

Brett
0
 

Expert Comment

by:clangl
ID: 8187480
Try using the ascii representation like this InStr(1, Check4Charactor, Chr(Ascii Representation for whatever special character you need)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:kevmeist
ID: 8189726
With

Public Const gblstrDefault_Doctor = "K. 'Hong, M.D."


Dim a As Integer

a = InStr(gblstrDefault_Doctor, "'")

After executing the above instruction, a returns a value of 4.
0
 
LVL 1

Accepted Solution

by:
FunkyMeister earned 120 total points
ID: 8200031
For your textbox:

At the top of your code

Private Const BadKeys = Chr(34)+"'-" ' Quote = CHR(34)



Private Sub textbox_KeyPress(KeyAscii As Integer)
 If Instr(BadKeys,Chr(KeyAscii)) Then KeyAscii = 0
End Sub

Snacks on the key if it's bad.  Since KeyAscii isn't being ByVal'ed, you're hitting the actual Ascii code that'll wind up going to the input window.  Effectively, you're killing the keys form working in that textbox
0
 

Expert Comment

by:itcprog
ID: 8208495
Try this little function.

Public Function CheckBadChar(strSourceString as String)
CheckBadChar = True 'Disallow by Default to be on the safe side.

if instr(strSourceString,"-") <> 0 then exit function 'Check for Minus
if instr(strSourceString,chr(34)) <> 0 then exit function 'Check for Double Quote
if instr(strSourceString,"'") <> 0 then exit function 'Check for Single Quote

'Add more here if you need them.

CheckBadChar = False

End Function

Then to use it simply do this.

If CheckBadChar(Check4Charactor) then
 MsgBox "Avoid using ' - ' in your user name."
 Me.textBoxes(2).SetFocus
 Exit Sub
end if ' or you could use else or whatever.
0
 

Expert Comment

by:itcprog
ID: 8208507
Or alternatively just change the following line in your code to the new one.

Original:
If MyPos = True Then

To:
If MyPos <> 0 Then
0
 

Expert Comment

by:CleanupPing
ID: 8531830
Hi ADawn,
This old question (QID 20559580) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8958723
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

-->Accept FunkyMeister's comments as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

GPrentice00
EE Cleanup Volunteer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question