Consulting

Results 1 to 6 of 6

Thread: UserForm ListBox - click problem

  1. #1
    VBAX Regular
    Joined
    Feb 2015
    Posts
    6
    Location

    UserForm ListBox - click problem

    Hello,

    I have a problem with vba forms and a listbox. I have 10 items in a list. All items have a link to an another template to open and print or show userForm etc. (AutoNew every template). However, sometimes when I click on, for example, the 1st item of a list, it is opened a 2nd item. MS Word mark the first though. Everytime Word opens the item below I click. To open the first one I have to click somewhere else and click again. This error appears only once until I close a form, then I can click and Word opens right document. After a new start it is all over again.

    INFO:
    Office 2007
    windows are modal
    Example (sorry for deleting some items, I have to):
    chyba.jpg

    Thanks for any advice how to fix this
    Martin

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,338
    Location
    Without seeing your code/form it is hard to say.
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Regular
    Joined
    Feb 2015
    Posts
    6
    Location
    Hello, here is a sample of the code inide of form, except dir$ which is in AutoNew Module as Public
         'In module AutoNew Public dir$ and then in Sub Main() dir$ = Options.DefaultFilePath(wdWorkgroupTemplatesPath) 
    
    '----------------------------------------------
    'Form code
    '----------------------------------------------
    Dim SeznamVitInv(8)
    
    Private Sub lstObecnei_Click()
       Documents.Add Template:=dir$ + "\" + SeznamVitInv(lstObecnei.ListIndex)
    End Sub
    
    Private Sub UserForm_Activate()
       With frmVIIN
         With .lstObecnei
          .AddItem "Soubor pojistných podmínek Vital Invest ze dne 22.4.2015 .......................................................KPPVIN27"
          .AddItem "Informace pro zájemce o pojištění Vital Invest ze dne 22.4.2015 ..................................................KPPVIPI4"
          .AddItem "Věrnostní bonus ..........................................................................................................KPVERBON"
          .AddItem "Finanční dotazník .........................................................................................................KPFINDOT"
          .AddItem "Doplňující informace k pojistným produktům obsahujícím investiční složku .......................................IPZI"
          .AddItem "Dodatečné informace k fondu KB Privátní správa aktiv 4 Popular..................................................KPVIIPSA"
          .AddItem "Prohlášení klienta vztahující se k fondům v rámci svého investičního životního pojištění .......................KPINV65L"
          .AddItem "Dodatečné informace k fondu KB PSA 5D - Popular A ...............................................................KPPVIP5A"
          .ListIndex = -1
        End With
    
        SeznamVitInv(0) = "kppvin27.dot"
        SeznamVitInv(1) = "kppvipi4.dot"
        SeznamVitInv(2) = "kpverbon.dot"
        SeznamVitInv(3) = "kpfindot.dot"
        SeznamVitInv(4) = "IPZI.dot"
        SeznamVitInv(5) = "kpviipsa.dot"
        SeznamVitInv(6) = "kpinv65l.dot"
        SeznamVitInv(7) = "KPPVIP5A.dot"
      End With
    End Sub

  4. #4
    Frankly I would put the code in the macro that calls the userform rather than in the userform itself e.g.

    Sub RunProcess()
    Dim strDIR As String
    Dim SeznamVitInv(8) As Variant
    Dim oFrm As New frmVIIN
        strDIR = Options.DefaultFilePath(wdWorkgroupTemplatesPath) & Chr(92)
        SeznamVitInv(0) = "kppvin27.dot"
        SeznamVitInv(1) = "kppvipi4.dot"
        SeznamVitInv(2) = "kpverbon.dot"
        SeznamVitInv(3) = "kpfindot.dot"
        SeznamVitInv(4) = "IPZI.dot"
        SeznamVitInv(5) = "kpviipsa.dot"
        SeznamVitInv(6) = "kpinv65l.dot"
        SeznamVitInv(7) = "KPPVIP5A.dot"
        With oFrm
            With .lstObecnei
                .AddItem "Soubor pojistných podmínek Vital Invest ze dne 22.4.2015 .......................................................KPPVIN27"
                .AddItem "Informace pro zájemce o pojištení Vital Invest ze dne 22.4.2015 ..................................................KPPVIPI4"
                .AddItem "Vernostní bonus ..........................................................................................................KPVERBON"
                .AddItem "Financní dotazník .........................................................................................................KPFINDOT"
                .AddItem "Doplnující informace k pojistným produktum obsahujícím investicní složku .......................................IPZI"
                .AddItem "Dodatecné informace k fondu KB Privátní správa aktiv 4 Popular..................................................KPVIIPSA"
                .AddItem "Prohlášení klienta vztahující se k fondum v rámci svého investicního životního pojištení .......................KPINV65L"
                .AddItem "Dodatecné informace k fondu KB PSA 5D - Popular A ...............................................................KPPVIP5A"
                .ListIndex = -1
            End With
            .Show
            'Documents.Add strDIR & SeznamVitInv(.lstObecnei.ListIndex)
            MsgBox strDIR & SeznamVitInv(.lstObecnei.ListIndex)
        End With
        Unload oFrm
        Set oFrm = Nothing
    End Sub
    You can simply hide the form when the listbox is clicked, or hide it from the button that closes the userform.
    I have simply added a messagebox for testing as I don't have your templates.

    Private Sub lstObecnei_Click()
        Me.Hide
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Regular
    Joined
    Feb 2015
    Posts
    6
    Location
    I hoped there is some issue in this code. Unfortunately, a little bit issue is I cannot do that, because inside a one template, where is the macro AutoNew with Public dir$, is about 40+ forms and most of them has this listBox. I showed you just one of them I can try to rewrite it accroding to you (of course with some changes).

    In my opinion, it is a little bit more than VBA forms are able to handle. However, there is nothing I can do about it. I inherited this code, but with Word 2003 it worked fine.

  6. #6
    VBAX Regular
    Joined
    Feb 2015
    Posts
    6
    Location
    Is it possible, that when I converted the Main template (where all Listboxes are) to .dotm it fixed it? So it looks like some bug in old templates (vba) . I will be testing it more.

Tags for this 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
  •