473,569 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to remove aspostophe

Hi,

Can someone tell me how to remove aspostophe (') from user input.

I don't want to give any error message. Just want to remove or change it to
"" or null, such input when it appear anywhere on a specific field. e.g. if
user input abcd's. I want the final data on the database be look like abcds
or abcd s

MSAccess 2000

Anyone any idea ?

Many thanks in advance.

May 17 '07 #1
9 3991
"Smiley" <fi*********@go oglemail.comwro te in message
news:f2******** ***********@new s.demon.co.uk.. .
Hi,

Can someone tell me how to remove aspostophe (') from user input.

I don't want to give any error message. Just want to remove or change it
to "" or null, such input when it appear anywhere on a specific field.
e.g. if user input abcd's. I want the final data on the database be look
like abcds or abcd s

MSAccess 2000

Anyone any idea ?

Many thanks in advance.
There may well be a more elegant approach but this works for me.

*** CODE BEGINS ***

Sub libRemoveCharac ter(strSearchCh ar As String, strField As String, strTable
As String)

'Author: Keith Wilby
'Date: 27 May 2005
'Purpose: remove characters from fields

Dim db As DAO.Database, rs As DAO.Recordset, strSQL As String, intPosition
As Integer
Dim strSearchString As String, strNewString As String
Set db = CurrentDb

strSQL = "Select " & strField & " From " & strTable & " Where InStr(nz([" &
strField & "]),""" & strSearchChar & """)>0"
Set rs = db.OpenRecordse t(strSQL)
If rs.RecordCount = 0 Then GoTo ExitSub

With rs
.MoveFirst
Do Until .EOF
strSearchString = rs(strField)
intPosition = InStr(1, strSearchString , strSearchChar, 1) - 1 'Count
the characters before the offending character
strNewString = Left(strSearchS tring, intPosition) 'Add the
characters before the offending character
strNewString = strNewString _
& Right(strSearch String, Len(strSearchSt ring) - (intPosition + 1))
'Add the characters after the offending character
.Edit
rs(strField) = strNewString
.Update
'Debug.Print strNewString
intRecordCount = intRecordCount + 1 'Increment the count
.MoveNext
Loop
End With

ExitSub:
rs.Close
Set rs = Nothing
Set db = Nothing

End Sub

*** CODE ENDS ***

Call the sub from your form's After Update event and pass the search
character, field name and table name to it (Chr(39) represents the
apostrophe but you can pass any character to it):

Call libRemoveCharac ter(Chr(39), "MyField", "tblMyTable ")

I've never used it from a form's update event but I imagine it'll work OK.

HTH - Keith.
www.keithwilby.com

May 17 '07 #2
Smiley wrote:
Hi,

Can someone tell me how to remove aspostophe (') from user input.

I don't want to give any error message. Just want to remove or change it to
"" or null, such input when it appear anywhere on a specific field. e.g. if
user input abcd's. I want the final data on the database be look like abcds
or abcd s

I need to do this all the time, though in my case, I replace the ' with
'' for Oracle data entry.

Anyway, use the after update event of the text box control into which
the user is data entering.

Private Sub MyTextBox_After Update()
Replace Me.MyTextBox, "'", ""
End Sub

The above will remove the apostrophe after the user leaves the text box
(to go to the next data entry control, or to click an OK button, etc).

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
May 17 '07 #3
"Tim Marshall" <TI****@PurpleP andaChasers.Moe rtheriumwrote in message
news:f2******** **@coranto.ucs. mun.ca...
>
I need to do this all the time, though in my case, I replace the ' with ''
for Oracle data entry.

Anyway, use the after update event of the text box control into which the
user is data entering.

Private Sub MyTextBox_After Update()
Replace Me.MyTextBox, "'", ""
End Sub

The above will remove the apostrophe after the user leaves the text box
(to go to the next data entry control, or to click an OK button, etc).
Blimey Tim, that *is* simple. I've never come across the replace function
in VBA, there's always something new to learn. The function I posted is
still good for me because it's to replace characters in an Oracle database
with an HTML GUI.

Tip duly noted, thanks :-)

Keith.

May 17 '07 #4
"Tim Marshall" <TI****@PurpleP andaChasers.Moe rtheriumwrote in message
news:f2******** **@coranto.ucs. mun.ca...
>
Private Sub MyTextBox_After Update()
Replace Me.MyTextBox, "'", ""
End Sub
I've even been able to replace the middle chunk of my code with this
simplified version:

Do Until .EOF
strNewString = rs(strField)
strNewString = Replace(strNewS tring, strSearchChar, strReplaceChar)
.Edit
rs(strField) = strNewString
.Update
.MoveNext
Loop

Thanks again Tim.

Keith.

May 17 '07 #5
Why do you want to suppress the apostrophe? This places restrictions
on the user and creates artificial use of names etc. If it is because
it causes problems in submitting a search string this is easily
overcome. Microsoft databases can handle apostrophes, not sure about
others such as Oracle...

Most MS products interpret ' ' (that is two apostrophes one following
the other with no space) within a literal experssion as literally an
apostrophe. So the 'fred''s bear' will be the string fred's bear.
Instead of stripping it out add another apostrophe beside it.

This solution works very well and is extensive across Microsoft
products. For example to put an ampersand in a label or button use a
double ampersand eg Wine && Beer will become Wine & Beer in a label
whereas Wine & Beer in a label becomes wine_beer. A single ampersand
is interpreted as the action letter whereas && is interpreted
literally as ampersand.

Another way to overcome it is to use ascii 39 when building the string
for the search eg strSearch = "Fred" &asc(39) &"s Bear"
HTH
td
=============== =============== =============== ====

On May 17, 9:17 pm, "Smiley" <firework...@go oglemail.comwro te:
Hi,

Can someone tell me how to remove aspostophe (') from user input.

I don't want to give any error message. Just want to remove or change it to
"" or null, such input when it appear anywhere on a specific field. e.g. if
user input abcd's. I want the final data on the database be look like abcds
or abcd s

MSAccess 2000

Anyone any idea ?

Many thanks in advance.

May 17 '07 #6
Hi Tim, Keith,

Thank you so much. I don't know much about MSAccess or VBA and have not used
it for years.

When Tim replied, I couldn't get it work and after Keith's reply, bingo.

You both are life saver.

Have a good weekend.

"Keith Wilby" <he**@there.com wrote in message
news:46******** **@glkas0286.gr eenlnk.net...
"Tim Marshall" <TI****@PurpleP andaChasers.Moe rtheriumwrote in message
news:f2******** **@coranto.ucs. mun.ca...
>>
Private Sub MyTextBox_After Update()
Replace Me.MyTextBox, "'", ""
End Sub

I've even been able to replace the middle chunk of my code with this
simplified version:

Do Until .EOF
strNewString = rs(strField)
strNewString = Replace(strNewS tring, strSearchChar, strReplaceChar)
.Edit
rs(strField) = strNewString
.Update
.MoveNext
Loop

Thanks again Tim.

Keith.

May 18 '07 #7
Hello TD,

Thank you for your advice. I don't know how to do the coding as such. I used
query to do the search. The aspostophe will delete the search query hence I
need to remove it when user input

If you don't mind, would you give me some coding as to how I would implement
such checking in a search.

MTIA
<ct***@internod e.on.netwrote in message
news:11******** **************@ h2g2000hsg.goog legroups.com...
Why do you want to suppress the apostrophe? This places restrictions
on the user and creates artificial use of names etc. If it is because
it causes problems in submitting a search string this is easily
overcome. Microsoft databases can handle apostrophes, not sure about
others such as Oracle...

Most MS products interpret ' ' (that is two apostrophes one following
the other with no space) within a literal experssion as literally an
apostrophe. So the 'fred''s bear' will be the string fred's bear.
Instead of stripping it out add another apostrophe beside it.

This solution works very well and is extensive across Microsoft
products. For example to put an ampersand in a label or button use a
double ampersand eg Wine && Beer will become Wine & Beer in a label
whereas Wine & Beer in a label becomes wine_beer. A single ampersand
is interpreted as the action letter whereas && is interpreted
literally as ampersand.

Another way to overcome it is to use ascii 39 when building the string
for the search eg strSearch = "Fred" &asc(39) &"s Bear"
HTH
td
=============== =============== =============== ====

On May 17, 9:17 pm, "Smiley" <firework...@go oglemail.comwro te:
>Hi,

Can someone tell me how to remove aspostophe (') from user input.

I don't want to give any error message. Just want to remove or change it
to
"" or null, such input when it appear anywhere on a specific field. e.g.
if
user input abcd's. I want the final data on the database be look like
abcds
or abcd s

MSAccess 2000

Anyone any idea ?

Many thanks in advance.


May 18 '07 #8
Keith Wilby wrote:
Blimey Tim, that *is* simple. I've never come across the replace
function in VBA, there's always something new to learn. The function I
posted is still good for me because it's to replace characters in an
Oracle database with an HTML GUI.
Replace was new with A2000 and for my A97 apps, I used a public function
somewhat similar to yours, I think, that I got off the Access Web.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
May 20 '07 #9
ct***@internode .on.net wrote:
Most MS products interpret ' ' (that is two apostrophes one following
the other with no space) within a literal experssion as literally an
apostrophe. So the 'fred''s bear' will be the string fred's bear.
Instead of stripping it out add another apostrophe beside it.
FYI, that's the way to do it for Oracle (and probably MS SQL, as well.
In Oracle, the ' is the same as the " in VBA.

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
May 20 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
55536
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are also removed) So far I have (val is value, ar is array, returns new array):
11
3060
by: Tony Johansson | last post by:
Hello! I have some problem with STL function remove I have two classes called Handle which is a template class and Integer which is not a template class. The Integer class is just a wrapper class for a primitive int with some methods. I don't show the Integer class because it will not add any information to my problem. Main is using some...
6
4933
by: Arne Claus | last post by:
Hi If've just read, that remove() on a list does not actually remove the elements, but places them at the end of the list (according to TC++STL by Josuttis). It also says, that remove returns a new, logical end pointer, so that the following myList::iterator end = myListObj.remove(myInt); myListObj.erase(end, myListObj.end()); is...
3
3795
by: Don | last post by:
My user control has a combobox with an arraylist attached to it along with custom add and remove methods. The "Add" method is working great. However I don't understand why the "Remove" method isn't working. It neither removes the item from the arraylist nor from the combobox like it's supposed to do. A couple of notes: cbx is the name of...
3
5385
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some example first:
6
7163
by: tshad | last post by:
Is there a reason to use session.remove over session.contents.remove? Don't they both remove the key and data from the contents collection? I assume that session(x) = nothing does essentially the same thing but is actually deleted later by the GC. Thanks, Tom
7
6591
by: Susan Mackay | last post by:
I have a data table that is connected to a database table with a data adapter in the 'standard' manner. However I want to be able to remove selected rows from the data table (i.e. no longer include them in the set that is displayed to the user) but I don't want to delete the corresponding row from the database. I've tried using the...
6
5976
by: sam_cit | last post by:
Hi Everyone, I'm using remove() function to delete a file, and i observed the following behavior, Concerned file : sample.txt Operation : i open the file in read mode and don't close the file. remove() returns -1 and the file is not deleted. The above operation is successful when i close the file just before
10
18054
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, I wanted to go through each entry(?) of ArrayList and remove some particular entry. So I tried following but it throws exception at runtime: foreach (myEntry entry in myArrayList) { // do something... if (entry.fieldA == 0)
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.