Results 1 to 12 of 12

Thread: Form Text Field

  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,468
    Thanks
    30
    Thanked 61 Times in 57 Posts

    Form Text Field

    A two-part question, actually.

    1. If I insert a text form field and specify the length of the field as (anything, for that matter)...why can a user enter an "enter" and essentially botch the input field? Can I get around that?

    2. If I specify that the field should be a date in the form
    mm/dd/yy...it seems there's no point to that unless I run a macro afterward. The date format seems meaningless as the user could enter anything s/he wants as long as they don't exceed the field length (if specified).

    Or, as often happens, I'm being stupid about doing something in both of these cases. TIA.

  2. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Text Field

    Hi,

    I think you would have to use a macro on exit from the form field for both situations.

    For the first, examine the string for VBCR and VBLF and replace with a zero length string.

    It is valid to have "return" in the form field- for a multi line text entry, for instance.
    For the second, use 'if IsDate(activedocument.formfields("Text1").Result then' (where Text1 is the name of the textbox).

    There is some date editing on date form fields, but it's not complete. I entered "22 jan ddd" as a date, which was accepted by the form field, but rejected by the IsDate.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  3. #3
    Star Lounger
    Join Date
    Jan 2001
    Location
    Upstate NY, New York, USA
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Text Field

    Hi Kevin - Long time no hear from you! We seem to end up in the same places... odd isn't it? Hope all is well with you!

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,468
    Thanks
    30
    Thanked 61 Times in 57 Posts

    Re: Form Text Field

    [img]/w3timages/icons/laugh.gif[/img] Say, GREAT to hear from you again. How are the boys?

  5. #5
    Star Lounger
    Join Date
    Jan 2001
    Location
    Upstate NY, New York, USA
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Text Field

    Hi Kevin - the boys are great - thanks for asking. I tried to send you a private message so as not to clutter the board, but said you didn't exist! Will email you privately.

    Take care.

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Text Field

    I believe Geoff is correct here about needing validation code. And the best place to put that code is in the form Query_close event. If you know about this, great. If not, let me know and I'll post some sample "form control validation code".
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. #7
    Star Lounger
    Join Date
    Jan 2001
    Location
    Upstate NY, New York, USA
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Text Field

    I'd be interested to see some form control validation code please....I'm unfamiliar with the "form Query_close event" you mentioned.

    Thank you.

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Text Field

    One of the best "features" of VBA is the Query_close event. Takes care of keeping the form open if you don't want the user to proceed based on validation requirements. Really good events just absolutely send me.[img]/w3timages/icons/thinks.gif[/img]

    The application events in 2000 are also prime pleasers. The counterpart in 97 is a bit weak.[img]/w3timages/icons/yikes.gif[/img]

    Anyway, enough from the code junky in me. Here's a swatch of code from one of my recent forms:

    <pre>Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    Dim aCaseID As String

    aCaseID = drpCaseLoc + drpCaseType + txtCaseDigits + drpCaseAct
    Select Case CloseMode
    Case 0 'User clicked close from the control menu. Treat this as a CANCEL!
    Cancel = False 'Allow form to close. Read this as DO NOT CANCEL this close event

    Case 1 'The UNLOAD code in the OK button is attempting to execute.
    If Me.drpFactFinders.Text <> "" Then
    'No code yet
    End If
    If Me.drpOffLocation.Text = "" And Me.drpOffLocation.Visible = True Then
    MsgBox "You forgot to enter an office location. Try again.", vbCritical + vbOKOnly, "Data Entry Error"
    Me.drpOffLocation.SetFocus
    Cancel = True
    Exit Sub
    End If

    'Check for valid CaseID
    If vNet And Me.drpCaseLoc <> "" Then
    If Not CMSValidID(aCaseID) Then
    MsgBox "The Case No. entered is invalid. Try again.", vbCritical + vbOKOnly, "Data Entry Error"
    Me.drpCaseLoc.SetFocus
    Cancel = True
    Exit Sub
    Else
    With Me
    vReg = .drpCaseLoc.Value
    vCaseType = .drpCaseType.Value
    vNum = .txtCaseDigits.Value
    vAct = .drpCaseAct.Value
    If vNum <> "" Then
    vCaseID = vReg + vCaseType + vNum + vAct
    Else
    vCaseID = ""
    End If
    End With
    End If
    End If
    With Me
    vLocName = .drpOffLocation.Text
    vProof = chkProof.Value
    vFaxPages = txtPages.Text 'used for Fax cover sheet

    vDecNum = .txtDecNum.Text

    If drpAuthor.Text = "" Then
    vAuthor = vFullName
    Else
    vAuthor = drpAuthor.Text
    End If

    If lstTo.Visible Then
    BuildToList
    End If
    vSubject = UCase(.txtSubject.Text)
    End With
    frmPERBMAIN.cmdMiscGo.Enabled = False

    End Select

    End Sub
    </pre>


    There's more here than you need. The thing to note is this: if the form control does not have a valid value set the Cancel property to TRUE and exit the sub (event). This cancels the close event. As a thoughtful programmer I always set focus to the offending control so the user gets the point. Look up this event in the help, too.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  9. #9
    Star Lounger
    Join Date
    Jan 2001
    Location
    Upstate NY, New York, USA
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Text Field

    Thanks so much Kevin! There's a lot there to digest. I'll give it a look and will probably be back to you with questions. I appreciate your guidance on this matter.

  10. #10
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,468
    Thanks
    30
    Thanked 61 Times in 57 Posts

    Re: Form Text Field

    I suspect this is VBA code with which I'm not extremely familiar. Anything you should share would be appreciated.

    TIA

  11. #11
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Text Field

    Yes, it looks like the answer to the original post transends the scope of this forum and bleeds over into the VBA forum. All I can say, is dive right in and start learning VBA. Resources abound. Try this for starters:

    http://www.mvps.org/word/index.html
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  12. #12
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Re: Form Text Field

    Hi,

    The following Knowledge Base article deals with disabling the Enter key in a protected form.
    http://support.microsoft.com/support/kb/ar...s/Q187/9/85.ASP

    You may want to take a look at the other links on my forms page (which is not done but the links at the beginning are good).
    http://www.addbalance.com/usersguide/forms.htm

    Hope this helps.
    Charles Kyle Kenyon
    Madison, Wisconsin

Posting Permissions

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