From: Catharinus on
Hello to you all

is it possible to programmatically add a maskedbox to a form at
runtime?
thanks

Catharinus
From: David Youngblood on

"Catharinus" <csvanderwerf(a)planet.nl> wrote...
> Hello to you all
>
> is it possible to programmatically add a maskedbox to a form at
> runtime?

Assuming the Masked Edit control library is referenced in the project,

With Controls.Add("MSMask.MaskEdBox", "MaskEdBox1")
.Move 100, 100, 1200, 350
.Mask = "(###)-###-####"
.Visible = True
.SetFocus
End With


From: Catharinus on
On 21 apr, 12:45, "David Youngblood" <d...(a)flash.net> wrote:
> "Catharinus" <csvanderw...(a)planet.nl> wrote...
> > Hello to you all
>
> > is it possible to programmatically add a maskedbox to a form at
> > runtime?
>
> Assuming the Masked Edit control library is referenced in the project,
>
>     With Controls.Add("MSMask.MaskEdBox", "MaskEdBox1")
>         .Move 100, 100, 1200, 350
>         .Mask = "(###)-###-####"
>         .Visible = True
>         .SetFocus
>     End With

thnxs

but I still get errors. For example the Mask-property
maybe I should try better
thanks for now

Catharinus
From: Catharinus on
On 21 apr, 13:48, Catharinus <csvanderw...(a)planet.nl> wrote:
> On 21 apr, 12:45, "David Youngblood" <d...(a)flash.net> wrote:
>
> > "Catharinus" <csvanderw...(a)planet.nl> wrote...
> > > Hello to you all
>
> > > is it possible to programmatically add a maskedbox to a form at
> > > runtime?
>
> > Assuming the Masked Edit control library is referenced in the project,
>
> >     With Controls.Add("MSMask.MaskEdBox", "MaskEdBox1")
> >         .Move 100, 100, 1200, 350
> >         .Mask = "(###)-###-####"
> >         .Visible = True
> >         .SetFocus
> >     End With
>
> thnxs
>
> but I still get errors. For example the Mask-property
> maybe I should try better
> thanks for now
>
> Catharinus

I thought I should do it this way, because I want to use the mb
everywhere in the module:
when I use the code below, I get an error in the last line: type
mismatch
Private WithEvents mb As MaskEdBox
Private Sub Form_Load()

Licenses.Add ("MSMASK.Maskedbox")
Set mb = Nothing
Set mb = Me.Controls.Add("MSMask.MaskEdBox", "MaskEdBox1")
end sub
From: dwy on
"Catharinus" wrote:

> On 21 apr, 13:48, Catharinus <csvanderw...(a)planet.nl> wrote:
> > On 21 apr, 12:45, "David Youngblood" <d...(a)flash.net> wrote:
> >
> > > "Catharinus" <csvanderw...(a)planet.nl> wrote...
> > > > Hello to you all
> >
> > > > is it possible to programmatically add a maskedbox to a form at
> > > > runtime?
> >
> > > Assuming the Masked Edit control library is referenced in the project,
> >
> > > With Controls.Add("MSMask.MaskEdBox", "MaskEdBox1")
> > > .Move 100, 100, 1200, 350
> > > .Mask = "(###)-###-####"
> > > .Visible = True
> > > .SetFocus
> > > End With
> >
> > thnxs
> >
> > but I still get errors. For example the Mask-property
> > maybe I should try better
> > thanks for now
> >
> > Catharinus
>
> I thought I should do it this way, because I want to use the mb
> everywhere in the module:
> when I use the code below, I get an error in the last line: type
> mismatch
> Private WithEvents mb As MaskEdBox
> Private Sub Form_Load()
>
> Licenses.Add ("MSMASK.Maskedbox")
> Set mb = Nothing
> Set mb = Me.Controls.Add("MSMask.MaskEdBox", "MaskEdBox1")
> end sub

If you need events, why not add the control at design-time. I do not know of
a way to add events at run-time, so what advantage is there to add the contol
at run-time.

That said, copied from a working project. Control was added to the project
and "Remove information about unused ActiveX Controls" was unchecked in the
project properties.

Private WithEvents mb As MaskEdBox

Private Sub Form_Load()
Set mb = Nothing
Set mb = Me.Controls.Add("MSMask.MaskEdBox", "MaskEdBox1")
With mb
.Move 100, 100, 1200, 350
.Mask = "(###)-###-####"
.Visible = True
End With
Me.Show
mb.SetFocus
End Sub

Private Sub mb_Change()
Debug.Print "MaskEdBox1.Change " & mb.Text
End Sub