Public Function Badwords()

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Public Function Badwords()

Post by burrina »

I need to check against the code in this module to see if it meets the companies requirements or not. i.e.bad words not allowed
What is the best way to approach this?
If Statement
Case Statement
DLookup

tblbadwords
badwordid
badword

I would need to call this and check before allowing a user to send a message to another user.

Thanks,

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Public Function Badwords()

Post by burrina »

If DCount ("tblbadwords", "badword" >=1) And [badword] = Me.txtmsg)Then
MsgBox “You have entered a word that is not permitted! " & _
"Please revise your message wording." , vbCritical, "Bad Word Detected!"
End If

Is this correct? txtmsg is the field that would contain the bad word(s)

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Public Function Badwords()

Post by burrina »

Think I worked it out.
If DCount("badword", "tblBadWords", "badword = '" & Me.txtmsg.value & "'") > 0 Then

MsgBox “You have entered a word that is not permitted! " & _

"Please revise your message wording." , vbCritical, "Bad Word Detected!"

End If

Me.txtmsg.SetFocus

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Public Function Badwords()

Post by StuartR »

Be very careful with this kind of thing. A few years ago, members of the UK parliament couldn't send messages that referred to Essex or Scunthorpe, due to a poor implementation of a bad words filter.
StuartR


User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Public Function Badwords()

Post by burrina »

Thanks, I am only using it for fowl or abusive language. The nasty ones. If management wants to amend that, it's on them.

Thanks,

User avatar
HansV
Administrator
Posts: 78237
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Public Function Badwords()

Post by HansV »

Also: the code as is will only display a warning if txtmsg is equal to a "bad word", but not if txtmsg contains a "bad word" in addition to other text. You could remedy this by using

Code: Select all

    If DCount("*", "tblBadWords", Me.txtmsg.Value & " Like '*' & [badword] & '*'") > 0 Then
but keep Stuart's caveat in mind.
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Public Function Badwords()

Post by burrina »

Many Thanks, missed that.

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Public Function Badwords()

Post by StuartR »

Hans, did you try your version with words like Essex and Scunthorpe. It looks very like the code that caused havoc for lots of our MPs
StuartR


User avatar
HansV
Administrator
Posts: 78237
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Public Function Badwords()

Post by HansV »

Depending on the bad word list, the code would indeed put up a warning for those names.

To write a really good version would be more complicated. You'd have to loop through the records of the bad words table, and either parse txtmsg into separate words, or use a clever regular expression to check it. It would also be much slower, but if the list of bad words isn't too long, you probably wouldn't notice it.
Best wishes,
Hans

User avatar
kdock
5StarLounger
Posts: 720
Joined: 21 Aug 2011, 21:01
Location: The beautiful hills of Western North Carolina

Re: Public Function Badwords()

Post by kdock »

burrina wrote:
29 Dec 2020, 11:12
Thanks, I am only using it for fowl or abusive language. The nasty ones. If management wants to amend that, it's on them.
burrina, Essex and Scunthorpe are not bad words in and of themselves, but they do contain them. See if you can follow Hans' advice to parse the message to individual words and only check whole words.

Kim
"Hmm. What does this button do?" Said everyone before being ejected from a car, blown up, or deleting all the data from the mainframe.

User avatar
kdock
5StarLounger
Posts: 720
Joined: 21 Aug 2011, 21:01
Location: The beautiful hills of Western North Carolina

Re: Public Function Badwords()

Post by kdock »

And may I say how typical it is to try to make computers do something the bad word users seem not to be able to do -- just not use them. Honestly, you'd think anyone with a lick of sense would realize that... oh, wait... Never mind.

Kim
"Hmm. What does this button do?" Said everyone before being ejected from a car, blown up, or deleting all the data from the mainframe.

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Public Function Badwords()

Post by burrina »

Thanks so much, I have since updated the code a LOT. My list is only about 20 names, maybe they will want t use more, up to them.
Yes, commonsense and good manners are a rare thing nowadays.
A have a very good friend who lives in North Carolina.
Happy Holidays,