pop up message

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

I have a subform and need to have a pop up message box in
case, if user types in a certain word in a memo field such
us 'send', then it pops up (or warning message) and
says 'to update the Main form'. Is it doable? if yes,
how... many thanks,
 
Hi Tom,

Use the Change event of the field control and search the Text property of
the control using the InStr() function to test for instances of a word. For
example:

----------
If InStr(1, MyTextBox.Text, "Hello") <> 0 Then
Call MsgBox("Your entry contains the word 'Hello'")
End If
----------

If the InStr function returns a 0 (zero), then the string was not found.

Hope this helps,
- Glen
 
Tom,

In the database Window, goto Forms. Select the form where the control is and
click 'Design' at the top (or right click on the form and click 'Design
View'). Then, right click on the memo field and click 'Properties'. In the
box that pops up there will be a tab labelled 'Event'. Click on this tab and
scroll down to On Change. Next, Click the button with the 3 ... and then
select 'Code Builder' from the list. You are now in the code window for
Visual Basic and should have something that looks as follows:

Private Sub txtSomeControl_Change()

End Sub

A control has many events (Before Update, Mouse Down, Click). If you paste
the code below between the Private Sub... End Sub... lines then the code
will 'run' every time the user make a change to the control. Might I add
that you dont use the Change Event, use After Update (sorry Glen) - Follow
the steps above but look for After Update in the Event list as this will
only check for the word after the user has finished typing in the whole
line. The end result will look as follows:

Private Sub txtSomeControl_AfterUpdate()

If InStr(1, Me.txtSomeControl, "Hello") <> 0 Then ' Using .Value not
..Text as this is always available
Call MsgBox("Your entry contains the word 'Hello'")
End If

End Sub

Replace txtSomeControl with the name of the field you want to check.

HTH,

Neil.
 
It worked !!!!!!!!!!
Thank you a lot gyus,
I have another question: the key word that launches the
MsgBox is "Approval", how can I make it work, if user
types in Appr instead of Approval?
 
I dont know if you can use wildcards with the InStr function but you may.
Try changing the code to:

If InStr(1, Me.txtSomeControl, "Appr*") <> 0 Then

HTH,

Neil.
 
Neil,
I tried the same thing, it didn't work. But that's OK,
more important is the 'approval'.
Is it possible to launch a Message Box, when user updates
the memo field, regardless typing the "approval", if
another txt field is empty?
Thanks,
 
Tom,

You dont need the * to check. Just use:

If InStr(1, Me.txtSomeControl, "Appr") <> 0 Then

The code for the empty text field is as follows:

' Check the field is not blank and is not null
If Me.txtControlThatMayBeBlank = "" Or
IsNull(Me.txtControlThatMayBeBlank) Then
' The field doesn't contain a value
' Code goes here to display messagebox
End If

I would combine the 2 so that they have to different message box's. The
final result could look something like:

Private Sub txtSomeControl_AfterUpdate()

If InStr(1, Me.txtSomeControl, "Appr") <> 0 Then
' Display a message to the user
Call MsgBox("You have typed in a word that contains the word Appr
into txtSomeContol")
End If

' Check the field is not blank and is not null
If Me.txtControlThatMayBeBlank = "" Or
IsNull(Me.txtControlThatMayBeBlank) Then
' The field doesn't contain a value
Call MsgBox("txtControlThatMayBeBlank does not contain a value.
Please Retry.")
End If

End Sub

HTH,

Neil.
 
Back
Top