Below are two functions which I find really useful.  They work together.  In
your application, just do the following:

SetFieldTextFromStr(fldIDgoesHere, str);

Voila!  I hope this helps.
Regards,

Tim Astle



/***********************************************************************
 *
 * FUNCTION:    SetFieldTextFromHandle()
 *
 * DESCRIPTION: Sets Field Text by using a Handle
 *
 * PARAMETERS:  - fldID
 *    - txtH
 *
 * RETURNED:    field pointer
 *
 ***********************************************************************/
FieldPtr SetFieldTextFromHandle(Word fldID, Handle txtH)
{
     Handle oldTxtH;
     FormPtr frm;
     FieldPtr fld;

     // Get the Active Form
     frm = FrmGetActiveForm();

     // Get the Pointer to the Field
     fld = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, fldID));

     // Error?!
     ErrNonFatalDisplayIf(!fld, "Incorrect Field Specified");

     // Swap handles!
     oldTxtH = FldGetTextHandle(fld);
     FldSetTextHandle(fld, txtH);

     // Clear field display
     FldEraseField(fld);

     // Draw field display
     FldDrawField(fld);

     // Free some memory baby!
     if(oldTxtH)
          MemHandleFree(oldTxtH);

     // Return the field
     return(fld);
}


/***********************************************************************
 *
 * FUNCTION:    SetFieldTextFromStr()
 *
 * DESCRIPTION: Sets Field text from a String
 *
 * PARAMETERS:  - fldID
 *    - str
 *
 * RETURNED:    field pointer
 *
 ***********************************************************************/
FieldPtr SetFieldTextFromStr(Word fldID, CharPtr str)
{
     Handle txtH;

     // Create a handle to the string
     txtH = MemHandleNew(StrLen(str) + 1);

     // If the handle is false...
     if(!txtH)
          return(NULL);

     // Use the newly created handle to copy the string info to it
     StrCopy(MemHandleLock(txtH), str);

     // Unlock it
     MemHandleUnlock(txtH);

     // Use this handle to set the Text to the Field
     return(SetFieldTextFromHandle(fldID,  txtH));
}

--

Tim Astle





-- 
For information on using the ACCESS Developer Forums, or to unsubscribe, please 
see http://www.access-company.com/developers/forums/

Reply via email to