home *** CD-ROM | disk | FTP | other *** search
/ DOS Wares / doswares.zip / doswares / DATABASE / DBASE5 / CUA_SAMP.ZIP / LOOKVAL.PRG < prev    next >
Encoding:
Text File  |  1994-06-24  |  6.2 KB  |  168 lines

  1. FUNCTION LookVal
  2. PARAMETERS pThis, pForm
  3. *----------------------------------------------------------------------------
  4. * NAME
  5. *   LookVal() - Generic Lookup validation routine.  
  6. * DESCRIPTION
  7. *   Search the lookup table using the value in the trigger field.
  8. *   If it matches, then update any DataLinks that are connected to
  9. *   the lookup table.
  10. *   If it doesn't match, display a browse table if Help and Fill is 
  11. *   active.  Otherwise, trigger an error.
  12. *
  13. *----------------------------------------------------------------------------
  14. #include "talkoff.hdb"
  15.  
  16.     PRIVATE lReturn, lVoid, cLookErr, cBrowStat, lExact, lNear, ;
  17.             searchFor
  18.  
  19.     searchFor = pThis.Value
  20.  
  21.     lExact = SET( "EXACT" ) = "ON"
  22.     lNear = SET( "NEAR" ) = "ON"
  23.  
  24.     *----------------------------------------------
  25.     *-- International, Translate these strings only
  26.     *----------------------------------------------
  27.     cLookErr  = [Lookup value not found in: ]
  28.     cBrowStat = [Select the desired value and press Enter to choose it] 
  29.     *--------------------------
  30.     *-- End translation section
  31.     *--------------------------
  32.  
  33.     lReturn = .F.
  34.     SELECT (pThis.LookAlias)
  35.  
  36.     *------------------------------------------------
  37.     *-- Does the value match one in the lookup table?
  38.     *------------------------------------------------
  39.     IF SEEK( m->searchFor )
  40.  
  41.         *------------------------------------------------------
  42.         *-- Update and of the lookup table fields that might be
  43.         *-- on the form.
  44.         *------------------------------------------------------
  45.         DO LookRef WITH ALIAS(), m->pThis
  46.  
  47.         *-------------------------------------------------
  48.         *-- If "Copy corresponding fields" is active, then
  49.         *-------------------------------------------------
  50.         IF TYPE( "pThis.LookAll" ) = "L" .AND. pThis.LookAll
  51.  
  52.             *--------------------------------------------
  53.             *-- Post the lookup table field values to the
  54.             *-- corresponding fields in the main file
  55.             *--------------------------------------------
  56.             DO LookCopy WITH m->pThis
  57.  
  58.         ENDIF
  59.         lReturn = .T.
  60.     ELSE
  61.         *-----------------------------------------------------------------
  62.         *-- If "Look no help" is active, display the lookup failed message
  63.         *-----------------------------------------------------------------
  64.         IF TYPE( "pThis.LookNoHelp" ) = "L" .AND. pThis.LookNoHelp
  65.  
  66.             *-----------------------------------
  67.             *-- Set up the error display message
  68.             *-----------------------------------
  69.             pThis.ValidErrorMsg = cLookErr + pThis.LookAlias
  70.  
  71.         ELSE
  72.             *------------------------------------------------------
  73.             *-- "Help no fill" is active, so build the Browse table
  74.             *------------------------------------------------------
  75.             DEFINE BROWSE LookUp
  76.             Lookup.Top           =  pThis.Top + 2
  77.             Lookup.Left          =  10
  78.             Lookup.Key           =  "LookKey"
  79.             Lookup.OnMouseDblClk =  "LookKey"
  80.             Lookup.Sizeable      =  .T.
  81.             Lookup.Moveable      =  .T.
  82.             Lookup.MDI           =  .F.
  83.             Lookup.Width         =  67
  84.             Lookup.Alias         =  ALIAS()
  85.             Lookup.StatusMessage =  m->cBrowStat
  86.             Lookup.ProcFile      =  "LookKey.prg," + HOME() + "FormRun.dbo"
  87.             Lookup.Action        = .F.
  88.  
  89.             *------------------------------------------------------
  90.             *-- Re-seek with NEAR active and EXACT off to get close
  91.             *------------------------------------------------------
  92.             SET NEAR ON
  93.             SET EXACT OFF
  94.             SEEK ( m->searchFor )
  95.             SET NEAR OFF
  96.             SET EXACT ON
  97.  
  98.             *--------------------------------------------------------
  99.             *-- Open the Browse as Modal so the user can pick a value
  100.             *--------------------------------------------------------
  101.             lVoid = LookUp.ReadModal()
  102.  
  103.             *--------------------------------------------
  104.             *-- Did the use pick a value from the Browse?
  105.             *--------------------------------------------
  106.             IF LookUp.Action
  107.  
  108.                 *-------------------------------------------------
  109.                 *-- Get the value from the lookup table and put it
  110.                 *-- in the trigger entryfield value.
  111.                 *-------------------------------------------------
  112.                 pThis.Value = EVAL( pThis.LookAlias + "->" + pThis.LookField )
  113.  
  114.                 *------------------------------------------------------
  115.                 *-- Update and of the lookup table fields that might be
  116.                 *-- on the form.
  117.                 *------------------------------------------------------
  118.                 DO LookRef WITH ALIAS(), m->pThis
  119.  
  120.                 *-------------------------------------------------
  121.                 *-- If "Copy corresponding fields" is active, then
  122.                 *-------------------------------------------------
  123.                 IF TYPE( "pThis.LookAll" ) = "L" .AND. pThis.LookAll
  124.  
  125.                     *--------------------------------------------
  126.                     *-- Post the lookup table field values to the
  127.                     *-- corresponding fields in the main file
  128.                     *--------------------------------------------
  129.                     DO LookCopy WITH m->pThis
  130.  
  131.                 ENDIF
  132.                 lReturn = .T.
  133.             ELSE
  134.  
  135.                 *-----------------------------------
  136.                 *-- Set up the error display message
  137.                 *-----------------------------------
  138.                 pThis.ValidErrorMsg = cLookErr + pThis.LookAlias
  139.  
  140.             ENDIF
  141.         ENDIF
  142.     ENDIF
  143.  
  144.     *----------------------------
  145.     *-- Reset NEAR and EXACT back
  146.     *----------------------------
  147.     IF m->lNear
  148.         SET NEAR ON
  149.     ELSE
  150.         SET NEAR OFF
  151.     ENDIF
  152.  
  153.     IF m->lExact
  154.         SET EXACT ON
  155.     ELSE
  156.         SET EXACT OFF
  157.     ENDIF
  158.  
  159.     SELECT ( pForm.CurrMast )
  160.  
  161. #include "talkon.hdb"
  162. RETURN lReturn
  163. *-- EOF: LookVal(  )
  164.  
  165.  
  166.  
  167.  
  168.