Results 1 to 4 of 4

Thread: too long string

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Location
    Pakistan
    Posts
    24

    Arrow too long string

    i am getting "too long string" error from the following code from line with exclamation mark. In this textbox i am typing the text which is about 3 to 5 lines. how can i get rid of this error

    Private Sub cmdDoc_Click()
    Dim wordapp As Word.Application
    Dim thisdoc As Document
    Dim thisrange As Range
    Set wordapp = CreateObject("word.application")
    If wordapp Is Nothing Then
    MsgBox "could notstart word"
    End If

    wordapp.Documents.Open ("C:\documents and settings\administrator\application data\microsoft\templates\C-00.dot")
    Set thisdoc = wordapp.ActiveDocument
    thisdoc.FormFields(1).Result = txtName.Text
    thisdoc.FormFields(2).Result = txtFNo.Text
    thisdoc.FormFields(3).Result = txtRef.Text
    thisdoc.FormFields(4).Result = txtNo.Text
    thisdoc.FormFields(5).Result = txtSite.Text
    thisdoc.FormFields(6).Result = txtMic.Text ??????
    thisdoc.FormFields(7).Result = txtDiag.Text

    please help me

  2. #2
    Lively Member JustinLabenne's Avatar
    Join Date
    Jul 2005
    Location
    Ohio
    Posts
    64

    Re: too long string

    2-3 lines I am guessing is over 255 characters long in your case: Some info from msdn: http://support.microsoft.com/default...b;en-us;181110
    Justin Labenne
    www.jlxl.net

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: too long string

    I dont see how MS thinks that removing characters to make it fit to 255 is a "workaround"
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    Re: too long string

    a real work around is to Redim an array of strings

    Code:
    Dim Lenght as long, Count as Long
    Dim Arr() as String
    Length = len(YourObjetsText)
    
    Redim Arr(Length/255)
    
    for Count = 0 to Length
        Arr(Count) = mid$(YourObjetsText,Count* 255,255)
    next
    why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
    for every question you ask provide an answer on another thread.

Posting Permissions

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



Click Here to Expand Forum to Full Width