Trying to clear a MaskEdbox

Hi I'm trying to clear a MaskEdBox using this code but it will not work. The uncommented code works for textboxes, but I can't seem to get the code working for a MaskEdBox. Any solutions out there? I have tried both with uncommented code. I thought I should mention this in case I confuse some of you out there.

Dim Contrl1 As Control
'Dim contrl2 As Control

For Each Contrl1 In frmCustomer.Controls
If (TypeOf Contrl1 Is TextBox) Then Contrl1.Text = ""
Next Contrl1

' For Each contrl2 In frmCustomer.Controls
' If (TypeOf contrl2 Is MaskEdBox) Then contrl2.Text = ""
' Next contrl2

I have also tried mebPhone.Text = "" but of course it didn't work.

Thanks!!
[808 byte] By [OzzyOsbourne] at [2007-11-17 17:00:47]
# 1 Re: Trying to clear a MaskEdbox
If you have set the .MASK property of the MaskedEditBox, then you should be aware that you cannot just empty it by assigning .TEXT = "". This will cause an exception. Consider the following:

Public Sub ResetMaskedEdit(ctrl as MaskedEditBox)
' save the .MASK value
dim szMask as String
szMask = ctrl.Mask

' reset the mask
ctrl.Mask = ""

' reset the text
ctrl.Text = ""

' re-apply MASK
ctrl.Mask = szMask
End Sub

You can call this subroutine and pass in the MaskedEditBox control and it will clear it up properly without error.

Good Luck,
-Cool Bizs
coolbiz at 2007-11-10 0:23:03 >
# 2 Re: Trying to clear a MaskEdbox
Originally posted by coolbiz
If you have set the .MASK property of the MaskedEditBox, then you should be aware that you cannot just empty it by assigning .TEXT = "". This will cause an exception. Consider the following:

Public Sub ResetMaskedEdit(ctrl as MaskedEditBox)
' save the .MASK value
dim szMask as String
szMask = ctrl.Mask

' reset the mask
ctrl.Mask = ""

' reset the text
ctrl.Text = ""

' re-apply MASK
ctrl.Mask = szMask
End Sub

You can call this subroutine and pass in the MaskedEditBox control and it will clear it up properly without error.

Good Luck,
-Cool Bizs

Thanks for replying!!!!
I tried it but I got the following errors.

1. Can't find project or library.
2. Then I get my References box from the Project menu. I'm not sure which one to select in the references box or if I'm doing something else wrong.
OzzyOsbourne at 2007-11-10 0:24:06 >
# 3 Re: Trying to clear a MaskEdbox
Sorry ... replace MaskedEditBox (in the parameter) to MaskEdBox.

-Cool Bizs
coolbiz at 2007-11-10 0:25:06 >
# 4 Re: Trying to clear a MaskEdbox
HI Cool Bizs,
Thanks a lot for helping me.
I tried it but it still wouldn't work. I put the code you sent me in a a code module as a public function and called it in a command button. I get an error on the call statement in the command button. It gives me an error saying Argument not optional.

Here's the code in the code module:

Public Function Reset_Mask(ctrl As MaskEdBox)
' save the .MASK value
Dim szMask As String
szMask = ctrl.Mask

' reset the mask
ctrl.Mask = ""

' reset the text
ctrl.Text = ""

' re-apply MASK
ctrl.Mask = szMask
End Function

Here's the code where I call it:

Private Sub cmdNew_Click()

Dim Contrl1 As Control

For Each Contrl1 In frmCustomer.Controls
If (TypeOf Contrl1 Is TextBox) Then Contrl1.Text = ""
Next Contrl1

Call Reset_Mask


Thanks again for responding. Much appreciated!!!


cmdNew.Enabled = False
cmdNew.Visible = False
cmdAdd.Enabled = True
cmdAdd.Visible = True
cboCustomerID.Enabled = False
txtLastName.SetFocus

End Sub
OzzyOsbourne at 2007-11-10 0:26:01 >
# 5 Re: Trying to clear a MaskEdbox
Private Sub cmdNew_Click()
Dim Contrl1 As Control

For Each Contrl1 In frmCustomer.Controls
If (TypeOf Contrl1 Is TextBox) Then
Contrl1.Text = ""
elseif (TypeOf Contrl1 Is MaskEdBox) Then
call Reset_Mask(Contrl1)
end if
Next Contrl1

End Sub

Good Luck,
-Cool Bizs
coolbiz at 2007-11-10 0:27:03 >
# 6 Re: Trying to clear a MaskEdbox
Thanks a million Cool Bizs!!!
OzzyOsbourne at 2007-11-10 0:28:07 >