Hi,
I'm having a problem with the SetAutoFilter method and I can't figure this out.
Our company has made a template with several pivot tables and these pivot tables use two named ranges in the workbook. Each range has data on a seperate sheet and both sheet are completely independent of each other. In one sheet, our clients see all the information of the dossiers they created in our program, in the other sheet, they see all the information of the merges (automated generated Word-files as lettres) they did in our program.
We noticed that some of our clients have a huge database that is put in one those sheets and Excel can't handle all that information when updating the pivot tables.
We have implemented a filter in which our clients can select a number of years they want to have in the Excel file, this could limit the data in the generated Excel file and will make the pivot tables work. But the generated Excel file serves as an audit, so sometimes they want to see all the dossier information.
In our program, we check which named ranges are known in the Excel file, only the existing ranges will be used to update the client information.
If we use our template with both ranges, everything works great. If we remove one range in our template, everything works flawless as well. (We do have to remove the pivot tables that use the deleted range, but this has nothing to do with our problem)
We do want our clients to be able to make changes in their generated Excel files by removing some pivot tables or adding pivot tables of their own. In order to preserve these changes, we check for the named ranges in their Excel file and update the according sheet(s).
If we have a generated Excel file with both named ranges in them, we can make changes and have our program update both sheets without a problem. If we have a generated Excel file with only one of the two named ranges, we get an error though!
The error is caused by the function xls.SetAutoFilter(rowIndex, colIndex1, colIndex2). We tried moving this function up and downward in our procedure and it always fails on this function. Strangely enough, this function doesn't fail when we use it with our templates or with the generated Excel file that has both ranges. It only fails when we use a generated Excel file that has only one of both ranges.
The error we get is the following:
EAccessViolation: Vcl.ComCtrls.pas (line 33711): Access violation at address 0040A94A in module 'Smw.exe'. Read of address 0000000C.
SVN Revision (no svn build)
[Smw.exe] System.TObject.Free (Vcl.ComCtrls.pas, line 33711)
[ntdll.dll]
[Smw.exe] System.__linkp.Free (Vcl.ComCtrls.pas, line 33711)
[ntdll.dll]
[ntdll.dll]
[Smw.exe] _Uxlsescher.Tdrawinggroup.TDrawingGroup.EnsureDwgGroup
[Smw.exe] _Uxlsescher.Tdrawing.TDrawing.AddAutoFilter
[Smw.exe] _Uxlssheet.Tsheet.TSheet.SetAutoFilter
[Smw.exe] _Uxlsadapter.Xlsfile.TXlsFile.SetAutoFilter
[Smw.exe] Frmaudit.TAuditForm.FillFileDossiers (frmAudit.pas, line 708)
[Smw.exe] Frmaudit.TAuditForm.CreateFile (frmAudit.pas, line 520)
[Smw.exe] Frmaudit.TAuditForm.btnLastUsedFileClick (frmAudit.pas, line 285)
[Smw.exe] Vcl.Controls.TControl.Click (Vcl.Controls.pas, line 7357)
[Smw.exe] Vcl.Controls.TWinControl.WndProc (Vcl.Controls.pas, line 10084)
[Smw.exe] Vcl.Stdctrls.TButtonControl.WndProc
[Smw.exe] Vcl.Controls.DoControlMsg (Vcl.Controls.pas, line 10153)
[Smw.exe] Vcl.Controls.TWinControl.WndProc (Vcl.Controls.pas, line 10084)
[Smw.exe] Vcl.Forms.TCustomForm.WndProc
[Smw.exe] Dcsforms.TDcsForm.WndProc (DcsForms.pas, line 1497)
[Smw.exe] System.Classes.StdWndProc
[USER32.dll]
[USER32.dll]
[USER32.dll]
[USER32.dll]
[USER32.dll]
[USER32.dll]
[USER32.dll]
[USER32.dll]
[USER32.dll]
[USER32.dll]
[USER32.dll]
[USER32.dll]
[Smw.exe] Vcl.Controls.TWinControl.DefaultHandler (Vcl.Controls.pas, line 10125)
[Smw.exe] Vcl.Controls.TWinControl.WndProc (Vcl.Controls.pas, line 10084)
[Smw.exe] Vcl.Stdctrls.TButtonControl.WndProc
[Smw.exe] System.Classes.StdWndProc
[USER32.dll]
[USER32.dll]
[USER32.dll]
[USER32.dll]
[Smw.exe] Vcl.Forms.TApplication.ProcessMessage
Could you help us with this please?
When we put this function in commentary, our program works flawless with these generated files containing only one range, but then our data doesn't have a auto filter.
Thanks in advance!
Sincerely,
Tim Smet
Hi,
Hi Adrian,
I've send you the mail.
It's really strange that if we use a generated file with both range, that we can use the SetAutoFilter twice without a problem and that we can't use it when we use a generated file that only has one range.
both sheets and ranges are seperate from each other and somehow this fails when there is only 1 range present in the generated file. In our template, this doesn't seem to be a problem, then we can have only one range and the SetAutoFilter works flawless.
Hi
Hi Adrian,
Thanks for the quick response.
You're explanation seems logical. I just wanted to check this hoping that this wouldn't be the problem.
I hope you'll figure this error out, it's really confusing and we want to keep this feature.
Sincerely,
Tim Smet
Hi,
Hi Adrian,
Thanks for the fix. We tested our program again with your changes and now everything works (both the fix with the SetAutoFilter and the codename fixes).
Sincerely,
Tim Smet