PDA

View Full Version : UserForm ListBox - click problem



aamp
04-30-2015, 04:52 AM
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):
13282

Thanks for any advice how to fix this :)
Martin

gmaxey
04-30-2015, 05:52 PM
Without seeing your code/form it is hard to say.

aamp
05-04-2015, 05:20 AM
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

gmayor
05-04-2015, 06:06 AM
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

aamp
05-05-2015, 03:44 AM
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.

aamp
05-12-2015, 05:10 AM
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.