How to warn people to use a word in a text field

D

doyle60

I want to warn users that they must either use the word "Woven" or
"Knit" in a text field (but can use many other words as well).

I've tried this and varous other things like it:

If Text22 Not Like "*Woven*" or "*Knit*" Then
DoCmd.RunMacro ("ENTRYFORM2Macros.WovenKnit")
End If

The Text box is Text22 and its control source is Fabric. (I don't
know why I never correct the old Text box.)

So they can enter in the field "100% Cotton Knit" or "Silly-Billy
Woven".

But if they try and enter "50% Cotton 50% Spandex", they should get a
warning, not a restriction.

Thanks,

Matt





"You must either use the word 'Woven' or 'Knit' in your description."
 
S

Stefan Hoffmann

hi Matt,

I've tried this and varous other things like it:
If Text22 Not Like "*Woven*" or "*Knit*" Then
Try this:

If Not ( _
(Text22.Value Like "*woven*") Or _
(Text22.Value Like "*knit*") _
) Then
End If



mfG
--> stefan <--
 
E

egerds

Private Sub Text22_BeforeUpdate(Cancel As Integer)

Dim bln_Show_Message As Boolean

bln_Show_Message = True

If Text22 Like "*Woven*" Then
bln_Show_Message = False
Else

End If
If Text22 Like "*Knit*" Then
bln_Show_Message = False
Else
End If

If bln_Show_Message Then
MsgBox "You must either use the word 'Woven' or 'Knit' in your
description.", vbOKOnly, "warning, not a restriction"
End If

End Sub
 
D

dymondjack

Sometimes its easier to break it into different controls (put Woven/Knit in a
combobox with the LimitToList property set to false (which it is by default I
believe)). Then on the form's beforeupdate event you can format the value to
what you want it stored as.

Or, have you tried the InStr function?

If (InStr(1, Me.textbox, "woven") = 0) And _
(InStr(1, Me.textbox, "knit") = 0) Then
'run your macro
End If



--
Jack Leach
www.tristatemachine.com

- "First, get your information. Then, you can distort it at your leisure."
- Mark Twain
 
D

doyle60

I used the one by egerds and it works fine enough. I didn't want to
create a separate field, which is so wise for various reasons, because
there are just too many fields for data entry already and 98% of the
time they get this one right and are clear. A warning is best. Also,
it means I don't have to go a change all sorts of reports and forms.
This database is 10 years old and is very, very involved. Thanks,

Matt
 
D

dymondjack

No prob...

For future reference though, you can do this with an unbound field, and
reset the bound field with a calculated value on the form's BeforeUpdate
without having to change any underlying data/reports/other forms, etc. I do
it ocassionaly as a quick fix here or there.

Glad you got it working
--
Jack Leach
www.tristatemachine.com

- "First, get your information. Then, you can distort it at your leisure."
- Mark Twain
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top