PRB: Masked Edit May Not Show Empty When Bound Field is NullLast reviewed: June 19, 1997Article ID: Q170358 |
The information in this article applies to:
SYMPTOMSThe Masked Edit control may not show an empty value when it is bound to a field in a Microsoft Access table. If you set the Mask Property of the control and the bound field is null, the control will not display an empty mask. Instead, it will show the value from the last non-null field. If the first record displayed has a null field, the control will show an empty mask. However, as soon as the control displays a non-null field it will not display an empty mask for any other empty field. If the Mask Property is not set, null fields will display as empty in the Masked Edit control.
RESOLUTIONTo work around this problem, you can change the text property of the Masked Edit control to an empty string when the bound field to contains a null value:
Private Sub Data1_Reposition() 'Check to see if the record is empty or contains 'a zero length string. 'Note: The AllowZeroLength property of the field must be True. If IsNull(Data1.Recordset("Phone")) Or _ Data1.Recordset("Phone") = "" Then 'Set the Masked Edit Box to an empty string 'Note: This sets the DataChanged for MaskEdBox1 to True MaskEdBox1.Text = "(___) ___-____" bFieldNull = True 'The field has no value Else bFieldNull = False 'The field has a value End If 'Set the mask for the control MaskEdBox1.Mask = "(###) ###-####" End Sub Private Sub Data1_Validate(Action As Integer, Save As Integer) If MaskEdBox1.DataChanged Then 'Check to see if the Masked Edit Box has an empty string 'and that the field was empty when you moved to this record If MaskEdBox1.Text = "(___) ___-____" And bFieldNull Then 'If the control has an empty string and the field is null 'set the DataChanged to False so that you don't 'update the field MaskEdBox1.DataChanged = False 'If the control now has an empty string but the field 'had a value when moved to this record you want to remove 'the value from the field ElseIf MaskEdBox1.Text = "(___) ___-____" _ And Not bFieldNull Then 'Turn the mask off so you can save an empty record MaskEdBox1.Mask = "" MaskEdBox1.Text = "" Data1.UpdateRecord 'update the bound controls End If End If End Sub STATUSThis behavior is by design.
MORE INFORMATION
Steps to Reproduce Behavior
|
Keywords : vb4win vb5all VBKBAX VBKBComp VBKBCtrl kbprb
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |