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,
Public Function Badwords()
-
- 4StarLounger
- Posts: 550
- Joined: 30 Jul 2014, 23:58
Re: Public Function Badwords()
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)
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)
-
- 4StarLounger
- Posts: 550
- Joined: 30 Jul 2014, 23:58
Re: Public Function Badwords()
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
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
-
- Administrator
- Posts: 12577
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: Public Function Badwords()
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
-
- 4StarLounger
- Posts: 550
- Joined: 30 Jul 2014, 23:58
Re: Public Function Badwords()
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,
Thanks,
-
- Administrator
- Posts: 78237
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Public Function Badwords()
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
but keep Stuart's caveat in mind.
Code: Select all
If DCount("*", "tblBadWords", Me.txtmsg.Value & " Like '*' & [badword] & '*'") > 0 Then
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 550
- Joined: 30 Jul 2014, 23:58
Re: Public Function Badwords()
Many Thanks, missed that.
-
- Administrator
- Posts: 12577
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: Public Function Badwords()
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
-
- Administrator
- Posts: 78237
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Public Function Badwords()
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.
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
Hans
-
- 5StarLounger
- Posts: 720
- Joined: 21 Aug 2011, 21:01
- Location: The beautiful hills of Western North Carolina
Re: Public Function Badwords()
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.
-
- 5StarLounger
- Posts: 720
- Joined: 21 Aug 2011, 21:01
- Location: The beautiful hills of Western North Carolina
Re: Public Function Badwords()
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
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.
-
- 4StarLounger
- Posts: 550
- Joined: 30 Jul 2014, 23:58
Re: Public Function Badwords()
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,
Yes, commonsense and good manners are a rare thing nowadays.
A have a very good friend who lives in North Carolina.
Happy Holidays,