• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 489
  • Last Modified:

When I compile the VBA code I get an error : Variable not defined on line that says : Set Objettreeview = treeview

I have a reference to :      Comctl32.ocx and Mscomctl32.ocx

why does not it work
0
rduche
Asked:
rduche
  • 7
  • 4
  • 2
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Can you post the code you have?

mx
0
 
rducheAuthor Commented:

Private Sub UserForm_Initialize()

    Dim objTreeView As Object
    Dim objListImage As Object
    Dim objListView As Object
    Dim nodNew As Node
    Dim prg As Control, sbr As Control
    Dim intI As Integer
    Dim rstLevelI As Recordset, rstLevelII As Recordset, RstCode As Recordset
    Dim MotherCode As String
    Dim c As Integer

On Error GoTo HandleErr
    Set objListImage = ImageList
    Set objTreeView = TreeView     ' This is the treeview that produce the error Variable not defined)
    Set objListView = ListView
   
    Set wks = dao.Workspaces(0)
    Set SMS = wks.OpenDatabase(FilePath & "datadict.mdb")
       
    MotherCode = Application.ActiveInspector.ModifiedFormPages("Contact Info").MotherCode.Value

    objListView.View = 3
    objListView.ColumnHeaders.Add , , "Detail", 4800
    objListView.HideColumnHeaders = False
    objListView.LabelEdit = 1
   
    Set RstCode = SMS.OpenRecordset("Select * from tblKeyCodes where [MotherCode]='" & MotherCode & "' order by [key];")
   
    RstCode.MoveFirst
   
    While Not RstCode.EOF
       
        Set nodNew = objTreeView.Nodes.Add(, , "C" & Trim(Str(RstCode("ID"))), RstCode("Code"))
        RstCode.MoveNext
       
    Wend
    RstCode.Close
    ExpandCode objTreeView.Nodes(1)
    Me.Caption = MotherCode
ExitHere:
    Exit Sub

' Error handling block added by Error Handler Add-In. DO NOT EDIT this block of code.
' Automatic error handler last updated at 09-11-2000 17:22:37   'ErrorHandler:$$D=09-11-2000    'ErrorHandler:$$T=17:22:37
HandleErr:
    Select Case Err.Number
        Case Else
            MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "FormPopUp.UserForm_Initialize"  'ErrorHandler:$$N=FormPopUp.UserForm_Initialize
    End Select
' End Error handling block.
End Sub
0
 
rducheAuthor Commented:
The following ListView also shows the same erro
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Set objTreeView = TreeView

This needs to be (on the right side) the Name of the Treeview control on your form.

mx
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
In other words, you insert an new TreeView control on a form ... and the Name property might be something like TreeView0 ... of course, you can rename this if you like.

so, in code ... you would have something like this:

Private Sub Form_Load()
    Dim oTVW As TreeView
    Set otwm = Me.TreeView0
End Sub

Also ... where is this code located?

Private Sub UserForm_Initialize() ???

OK ... this is not Access ?

mx

0
 
rducheAuthor Commented:
I am sorry you are right this is not an access program. It is a VBA inside outlook 2007. It used to work in Outlook 2000 but does not work with the new outlook 2007. However, I am an Access programmer, I do program in VBA.   The problem stilll remains to be solved.

0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
ok... well, my guess is ... still the same consideration ...

'TreeView' ... is not defined anywhere ??

If you rem out the treeview error line ... do you get the same error on
    Set objListView = ListView

?

Is the Treeview Control actually in the ActiveX AddIns (Insert Ax Control) list ?  

I won't be on an A2007 machine until tonight ...

mx
   

0
 
harfangCommented:
mx is right, you probably don't have anything called "TreeView" on your form (this is the only explanation for "variable not defined"). If you do, notice that it's an ActiveX control, not a TreeView object. Hence, if you have inserted a "treeview control", and named it "acxTree", you could then:

    Dim twMyTree As TreeView

    Set twMyTree = acxTree.Object

Because the object in the ActiveX control is indeed a TreeView object...

(°v°)
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
<ot>
Hey Marcus ... while you are here ...
Question.  I have read this:
Say you have a (Select) query in design view in the query grid ... 2-3 tables, nothing special.  You make some changes (new fields, sorting, whatever).  According to what I read ... JET optimizes the query - creates the 'plan' when you Save in design view ... against the existing data at that time ... as opposed to ... when you actually Run the query (from say the query grid)  *after* saving it.  In fact, it says that IF .... you Run the query (from the query grid) ... and then Save again ... the plan goes away.

What is the reality here?

thx.mx

<ot/>
back to top
0
 
harfangCommented:
I don't know about that. I know that Jet reorganizes the order of tables in a FROM clause and some similar tweaking. The only information I have access to it this:

SaveAsText acQuery, "Query1", "Query1.txt"

You will see that the SQL string isn't stored anywhere, but perhaps the plan is (and just not exported). Maybe what you read confuses the SQL string with the plan?

(°v°)
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
I will dig up that article ... I believe from Access Advisor. The main question regarding optimizing is the sequence:

a) DesignView>>Make Changes>>Save (Jet Optimizes Now?)>> Run/Test  

Or

b) DesignView>>Make Changes>>Run/Test>>Save (Jet Optimizes Now?)

In some ways, it's a mutt point .. because Compact and Repair re-optimizes any saved queries anyway ... and I C&R mdb's I am working on all the time ... as I do production mdb's

thx for your input.

mx
0
 
rducheAuthor Commented:
To databaMX:

Thanks, I had to allow an Outlook 2007add-in  in the Trust Center the add-in : The :  Microsoft Outlook Add in for Data Collection and Publishing. Your last comment pointed me in the right direction

Thanks.   Answer me and write this comment in your answer and I will accept your answer as solution

0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Another thought ... you may have to allow the add-in into the Trust Center (aka insecurity center) ...

mx
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 7
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now