I am getting the error "Method or Data Member not found" for ListSubItems whenever I try to compile the project. I have added the SP6 component, MSCOMCTL.OCX. But still I am getting this error.
Public Function SetBoldToListItemInListView(lv As ListView, lvwItem As ListItem, bBold As Boolean) As Boolean
Dim i As Integer
On Error GoTo EH
ResetBoldInListView Not bBold, lv
lvwItem.EnsureVisible
For i = 1 To lvwItem.ListSubItems.Count
lvwItem.ListSubItems(i).Bold = True
Next
lvwItem.Bold = True
lvwItem.Selected = True
lv.Refresh
SetBoldToListItemInListView = True
ExitProc:
On Error Resume Next
Exit Function
EH:
Error_Handler "Support / CheckUncheckItemsInListView"
Resume ExitProc
End Function
This is an old question but for anyone still looking for an answer you need to add a component Microsoft Windows Common Controls 6.0 (SP6).
Go to Projects -> Components (Ctrl+ T) and check the checkbox for it.
Once this is added, you will also see extra components in the available GUI elements.
Related
I have a problem as below.
A program is written using early binding in VBA and it only works with all the references connected.
but there are some systems where the references are not connected and when the program is ran on those systems there is a compile error.
so I thought maybe I can use late binding to connect the references but it still shows compile error.
condition is that I cant convert the variables in code to late binding.
Public oPart As Part
Sub CATMain()
Dim refname()
Dim reffullPath()
Dim refGUID()
ReDim refname(5)
refname() = Array("INFITF,MECMOD", "ProductStructureTypeLib")
ReDim reffullPath(5)
reffullPath() = Array("D:\opt\ds\catia\B28_VWGROUP\win_b64\code\bin\MecModTypeLib.tlb", "D:\opt\ds\catia\B28_VWGROUP\win_b64\code\bin\PSTypeLib.tlb")
ReDim refGUID(5)
refGUID() = Array("{0D90A5C9-3B08-11D1-A26C-0000F87546FD}", "{5065F8B6-61BB-11D1-9D85-0000F8759F82}")
CheckAndAddReference refname(), reffullPath(), refGUID()
End Sub
Sub CheckAndAddReference(refname() As Variant, refLocation() As Variant, refGUID() As Variant)
Set VBAEditorx = CreateObject("MSAPC.Apc").VBE 'Application.VBE
Set vbProj = VBAEditorx.ActiveVBProject 'ActiveWorkbook.VBProject
For j = 0 To UBound(refname)
For i = 1 To vbProj.References.Count
RefCon = False
If vbProj.References.Item(i).Name = refname(j) Then
RefCon = True
Exit For
End If
Next
If RefCon = False Then
vbProj.References.AddFromFile refLocation(j)
End If
Next
End Sub
the first line "Public oPart As Part" , I cant make it as Object because there are many of these in original program.
the above line requires a reference called "INFITF,MECMOD" which is not connected in some systems.
when I try to late bind it, it is showing the error as
Compile error:
user type not defined
so I wanted to ask weather i can late bind the reference while the line "Public oPart As Part" remains same in the code without showing an error.
or I need to make all the early bound objects into "As Object".
I am coming across error 438 when running code to open 2 tabbed forms from 1 reference ID from another form; It opens the forms correct with the looks of the Data but shows the error -
Error Number: 438
Object doesn't support this property or method
I believe the error to be as to .filter isn't working, because a filter is already applied - however the results look correct as current the 2 sub tabbed forms open on the correct record but the error still shows every time
I would like the below code to run without the error can anyone make any suggestions - (not just error handling to ignore error)
Public Function Open()
On Error GoTo Err_LogError
Dim stLinkCriteria As String
Dim stLinkCriteria1 As String
stLinkCriteria = "[CaseID]=" & Me![ID]
stLinkCriteria1 = "[CaseID]=" & Me![ID]
Forms!frmHome!frmTabs.Form.Visible = True
Forms!frmHome!frmTabs.Form!frmLiveTasks.SetFocus
Forms!frmHome!frmTabs.Form!frmLiveTasks.Form.Filter = stLinkCriteria
Forms!frmHome!frmTabs.Form!frmLiveTasks.Form.FilterOn = True
Forms!frmHome!frmTabs.Form.Visible = True
Forms!frmHome!frmTabs.Form!frmLiveInfo.SetFocus
Forms!frmHome!frmTabs.Form!frmLiveInfo.Form.Filter = stLinkCriteria1
Forms!frmHome!frmTabs.Form!frmLiveInfo.Form.FilterOn = True
Exit Function
Err_LogError:
Call ErrorHandle
End Function
It transpired that the code worked - but the error was linked to another section of VBA
Say you have one slide with one chart on it, and you run this code(in a version of Office later than 2007):
Dim pptWorkbook As Object
Dim result As Object
Set pptWorkbook = ActivePresentation.slides(1).Shapes(1).Chart.ChartData.Workbook
Set result = pptWorkbook.ContentTypeProperties
You will generate an error:
Application-defined or object-defined error
I believe this is because "Smart tags are deprecated in Office 2010."(Source), Generally to avoiding this sort of issue from throwing an error and exiting your VBA you can take one of two different approaches:
//Method 1
If OfficeVersion <= 2007
Set result = pptWorkbook.ContentTypeProperties
//Method 2
On Error Resume Next // or GOTO error handler
Set result = pptWorkbook.ContentTypeProperties
Method one requires that you know the specific reason why the property would cause an error, which is easy in this case but may not be as easy with other properties. Method two requires that you use some form of error handling to deal with the error AFTER the fact, my understanding of most other Microsoft languages is that is typically discouraged(example, another example). Is this standard practice in VBA?
In VBA, is there any other way to determine whether a property of an object would throw an error if invoked, BEFORE invoking that property, and without knowing the specifics of that invoked property?
What I like to do for this situation is create a separate function that checks if the property exists and returns a Boolean. In this case it would look something like this:
Public Function CheckIfExists(targetObj As Object) As Boolean
Dim testObj As Object
On Error GoTo failedTest:
Set testObj = targetObj.ContentTypeProperties
CheckIfExists = True
Exit Function
failedTest:
CheckIfExists = False
End Function
Which would return false if that property causes an error and true if not-
Then modify your sub to be:
Public Sub FooSub()
Dim pptWorkbook As Object
Dim result As Object
Set pptWorkbook = ActivePresentation.slides(1).Shapes(1).Chart.ChartData.Workbook
If CheckIfExists(pptWorkbook) Then
Set result = pptWorkbook.ContentTypeProperties
End If
... rest of your code or appropriate error handling...
Hope this helps,
TheSilkCode
I have a crash file where I can see that one of my own VB6 user controls is responsible for the crash; i.e. one of its methods is part of the stack trace and I can see the line responsible.
From here, I'd like to inspect the state of its member variables. How do I do this?
Note: I also have the private symbols for my controls. The problem is being able to inspect "Me". The command !object address_of_Me doesn't seem to do the trick and so I'm at a loss.
Thank you.
It's been 10 years since I had to do this in VB6, but I remember a lot of Printer.Print statements in my past life :)
I used to do things like this for debugging (but not for release code)
Sub MySub
On Error Goto ErrorTrap
Dim intX as integer
Dim intY as integer
' do some horrible error here
Exit Sub
ErrorTrap:
Printer.Print "Error"
Printer.Print intX
Printer.Print intY
Printer.Print ...
End Sub
well, codeSMART have one option install global handle on your application first call to SetUnhandledExceptionFilter (win api) is should be installed when load your module main or master form when is closing the program so call to SetUnhandledExceptionFilter.
The code is little long so copy methods names y api calls
Public Sub InstallGlobalHandler()
On Error Resume Next
If Not lnFilterInstalled Then
Call SetUnhandledExceptionFilter(AddressOf GlobalExceptionHandler)
lnFilterInstalled = True
End If
End Sub
Public Sub UninstallGlobalExceptionHandler()
On Error Resume Next
If lnFilterInstalled Then
Call SetUnhandledExceptionFilter(0&)
lnFilterInstalled = False
End If
End Sub
Also here is Record Structure y apis declarations for the module
- CopyMemory
- SetUnhandledExceptionFilter
- RaiseException
' Public enums
-EExceptionType
-EExceptionHandlerReturn
-Private Const EXCEPTION_MAXIMUM_PARAMETERS = 15
' Private record structure
-Private Type CONTEXT
'Structure that describes an exception.
-Private Type EXCEPTION_RECORD
'Structure that contains exception information that can be used by a debugger.
-Private Type EXCEPTION_DEBUG_INFO
-Private Type EXCEPTION_POINTERS
Take a revised that How to route the exe exception back to VB6 app?
I'm maintaining a vb6 project(ActiveX DLL). When debugging, the app run into the following function:
Public Function HasValue(ByVal vValue) As Boolean
On Error GoTo Err
If IsMissing(vValue) Then
HasValue = False
ElseIf IsNull(vValue) Or Len(vValue) = 0 Then
HasValue = False
ElseIf isEmpty(vValue) Then
HasValue = False
Else
HasValue = True
End If
Exit Function
Err:
If IsArray(vValue) Or IsObject(vValue) Then
HasValue = True
Else
HasValue = False
End If
End Function
and it stops at the line
ElseIf IsNull(vValue) Or Len(vValue) = 0 Then
vValue is a custom object, contains some properties(obviously, not null).
Although I didn't put any break point there, the app stopped there and alerted error dialog saying that "Run-time error '438': Object doesn't support this property or method".
We had error handling code but the app didn't run to error handling code. It just stopped at the line causing the error and I had to stop the application.
Do you have any idea about that?
Thank you very much.
As far as getting the popup running in the debugger, it is probably related to your "Error Trapping" settings in the IDE. Go To Tools->Options->General and see what selected under "Error Trapping". At first glance it seems odd that your error handler is testing the vValue in the event of an error. It makes more sense to me based on my limited understanding of this method to move both the IsArray and IsObject conditions up into the main testing logic. Just my 2 cents :)
As far as i know vb6 does not support boolean short evaluation in
ElseIf IsNull(vValue) Or Len(vValue) = 0 Then
so Len(vValue) = 0 is executed even if IsNull(vValue) is true.
changing your code to
...
ElseIf IsNull(vValue) Then
HasValue = False
ElseIf Len(vValue) = 0 Then
HasValue = False
ElseIf ...
might solve the problem