Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2016
    Provided Answers: 1

    Unanswered: Inputbox code request

    this is a part of a VBA code to send mails using CDO and i'm using inputbox to enter mail address only like this

    PHP Code:
      Dim Mailto  As String          
    InputBox("Enter Mail Address""Enter Email Address")

    Mailto <> "" Then 
    ("Mail Will sent to " Mailto " please wait  "), vbMsgBoxRtlReading"Sending ..."
    MsgBox "message not sent , try again"vbCritical"Error"
    End If 
    i want to make it as input mask like mail :
    and i don't want the inputbox to accept this data on it until it match MASK

    how to code it ???

  2. #2
    Join Date
    Feb 2014

    You can't use an InputBox function if you want an InputMask feature.
    Anyway, it is difficult to design a control with an email InputMask cause of the multiple syntax of our email addresses :
    6. etc.

    So, a workarround consists to let a nomal textbox where you use RegularExpression on the BeforeUpdate Event.

    Private Sub txtRecipient_BeforeUpdate(Cancel As Integer)
    Dim vntEmail                                           As Variant
    Dim strMessage                                         As String
        vntEmail = Me.txtRecipient.Value
        If Not IsNull(vntEmail) Then
            If EmailIsValid(CStr(vntEmail), strMessage) = False Then
                MsgBox strMessage, vbExclamation, "Bad address"
                Cancel = True
            End If
        End If
    End Sub
    With the function stored into a module :
    Public Function EmailIsValid(ByVal MailAddress As String, ByRef Message As String) As Boolean
    Dim oRegExp                                            As Object ' regExp
    Set oRegExp = CreateObject("VBScript.RegExp")
        oRegExp.Pattern = "^([a-zA-Z0-9_\-])([a-zA-Z0-9_\-\.]*)@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$"
        EmailIsValid = True
        If oRegExp.test(MailAddress) = False Then
            EmailIsValid = False
            Message = "The mail address '" & MailAddress & "' you typed is not valid !"
        End If
        Set oRegExp = Nothing
    End Function

  3. #3
    Join Date
    Jun 2005
    Richmond, Virginia USA
    Provided Answers: 19
    Also, note that you can have the Visible Property of your 'roll-your-own' inputbox/Textbox set to No, in the Property Pane, then use code, such as

    InpBox.Visible = True

    triggered by whatever you were originally triggering the InputBox with, to make it 'pop up' and use


    InpBox.Visible = False

    in an event to make it disappear, like the native InputBox. I usually use the Double-Click event for Textbox for something like this.

    Note that the


    to set Focus elsewhere is needed because you cannot make a Control 'vanish' while it has Focus.

    Don't think this will interfere with the code that Argyronet has given you but don't think it will cause a problem.

    Linq ;0)>
    Last edited by Missinglinq; 09-03-16 at 15:09.
    Hope this helps!

    The problem with making anything that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts