Message Box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two fields in the form I want both of them to have the same equal data of tele each other and if the data is not same then display me a message. Note both fields are TEXT fields
 
Greetings Daud

This is a bit technical, so take your time...

1. Create a "PublicVariables" Module, and add the
following: -
Public Field1Blank,Field2Blank As Boolean
Public String1,String2 As String
Public MaxError As Integer
Public MsgValue

Save and close the Module

For each fields "On Exit" Procedure, add the following...
Field 1: -
If Me.Field1 = "" Then Field1Blank = True Else Field1Blank
= False
Call CompareFields

Field 2: -
If Me.Field2 = "" Then Field2Blank = True Else Field2Blank
= False
Call CompareFields


Create another Module "FormFunctions" and add the
following: -

Function CompareFields()
On Error Goto CompareErr
If Field1Blank=True Then Exit Function
If Field2Blank=True Then Exit Function
String1 = Forms![FormID]![Field1]
String2 = Forms![FormID]![Field2]
MaxError = StrComp (Field1,Field2,vbTextCompare)
If MaxError <> 0 Then Exit Function
MsgValue = MsgBox ("PUT MESSAGE
HERE",vbOkCancel+vbExclamation)
Forms![FormID]![Field1].SetFocus
Exit Function
CompareErr:
msgbox (err.number & ", " & err.description)
End Function

Save the module, compile the VBA Project then close.

Edit the programmes to reference the correct Form Name and
Field Names.

HTH



Tony C.
-----Original Message-----
I have two fields in the form I want both of them to have
the same equal data of tele each other and if the data is
not same then display me a message. Note both fields are
TEXT fields
 
Back
Top