Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-21-2020, 01:27 PM
gmaxey gmaxey is offline Formatting ID numbers to insert dashes in between some characters Windows 10 Formatting ID numbers to insert dashes in between some characters Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

That would depend on what type of field. If it is a content control in the document itself then something like this



Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
  Select Case ContentControl.Title
    Case "ID"
      If Not ContentControl.Range.Text Like "####-###-####" Then
        If IsNumeric(ContentControl.Range.Text) And Len(ContentControl.Range.Text) = 11 Then
           ContentControl.Range.Text = Format(ContentControl.Range.Text, "####-###-####")
        Else
          MsgBox "Please enter an eleven digit ID"
       End If
     End If
  End Select
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/

Last edited by macropod; 12-21-2020 at 02:16 PM. Reason: Added code tags
Reply With Quote
  #2  
Old 12-21-2020, 02:09 PM
shaun0406 shaun0406 is offline Formatting ID numbers to insert dashes in between some characters Windows 10 Formatting ID numbers to insert dashes in between some characters Office 2010
Novice
Formatting ID numbers to insert dashes in between some characters
 
Join Date: Dec 2020
Posts: 19
shaun0406 is on a distinguished road
Default

Sorry I didn't specify, I thought I specified which text form field I used.
I am using the legacy text field set to Regular text with max length to 11

from the code you provided, that made sense to me, but is there a keyword to change
"ContentControl" to legacy text field instead?

Thank You
Reply With Quote
Reply

Tags
autoformat, formating



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting ID numbers to insert dashes in between some characters How to insert paragraph character after every 500 characters? aditya_bokade Word VBA 28 11-13-2021 10:48 PM
Formatting ID numbers to insert dashes in between some characters Insert text longer 254 characters in word Esgrimidor Word VBA 7 03-16-2017 01:02 PM
Formatting ID numbers to insert dashes in between some characters Insert more than 500 characters on FormField Word by VBA Jow Word VBA 4 09-15-2016 04:06 AM
Formatting ID numbers to insert dashes in between some characters Is there a quick way to remove the dashes and parentheses from phone numbers? Stacy Excel 2 09-12-2014 07:03 AM
Macro to insert WordArt characters Jennifer Murphy Word VBA 1 02-25-2014 03:10 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:44 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft