Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Join Date
    Feb 2004
    Location
    London
    Posts
    46

    Post Unanswered: Mytreeview query

    Hiya,

    I'm using a Mytreeview activex example for a project I'm making at the moment.

    In short, I want to have a login screen that takes the value (a clocking number) from that and filters what the people can see in the tree view structure.

    I set up a query to test whether this would work. I put in a user ID in the query as the criteria and bingo.. I was able to establish different trees for different people. Great I thought! So off I set writing something that automates it.

    My idea was to take the value from the login screen (clocking number in the format example "b6666") and use that criteria to filter people records. This query ran from the onload function addnodes. My code in the query is as simple as it gets. I just use:

    [Forms!]![Mainform]![Textboxvalue] to extract the information

    This will not work for me at all. The query extracts exactly the information I'm after if I run it separately, though when running the form I get a "Run-time error 3061 too few parameters expected 1" message box come up.

    Now I'm pretty sure it's the code that populates the tree on the load command of the form. I feel it's the "Set Rst = DB.OpenRecordset" line.. would it be a recordset if it's in a query? Could be totally wrong. Does anyone have any ideas to why it works standalone but not generated from this code:

    thanks in advance!!
    --------------------------------------------------------------------------
    Sub AddNodes()

    ' Adds the data to the tree
    Dim DB As DAO.Database
    Dim Rst As DAO.Recordset
    Dim StrParent As String
    Dim StrChild As String


    ' create a recordset of tbk_obs_l
    Set DB = CurrentDb
    Set Rst = DB.OpenRecordset("Select qry_tree_access_main_form.* from qry_tree_access_main_form;")

    StrParent = ""
    StrChild = ""
    Rst.MoveFirst


    Do Until Rst.EOF = True



    'Build the Nodes for the TreeView Control
    ' level 1 is the parent
    ' loops through the recordset adding data to the tree

    With MyTreeView.Nodes


    On Error Resume Next

    StrParent = Rst![Department]
    StrChild = Rst![Department]

    .Add , , StrParent, StrChild

    End With

    Rst.MoveNext


    Loop



    StrParent = ""
    StrChild = ""
    Rst.MoveFirst

    'level 2 is the parent of level3 and the child of level 1

    Do Until Rst.EOF = True

    StrParent = Rst![Department]
    StrChild = Rst![OBS_L2]

    If StrChild <> "" And StrChild <> "N/A" Then

    With MyTreeView.Nodes

    .Add StrParent, tvwChild, StrChild, StrChild

    End With

    End If

    Rst.MoveNext

    Loop


    StrParent = ""
    StrChild = ""
    Rst.MoveFirst

    'level 3 is the parent of level4 and the child of level 2

    Do Until Rst.EOF = True

    StrParent = Rst![OBS_L2]
    StrChild = Rst![OBS_L3]

    If StrChild <> "" And StrChild <> "N/A" Then

    With MyTreeView.Nodes

    .Add StrParent, tvwChild, StrChild, StrChild

    End With

    End If

    Rst.MoveNext

    Loop

    StrParent = ""
    StrChild = ""
    Rst.MoveFirst

    'level 4 is the parent of level3 and has no children

    Do Until Rst.EOF = True

    StrParent = Rst![OBS_L3]
    StrChild = Rst![OBS_L4]

    If StrChild <> "" And StrChild <> "N/A" Then

    With MyTreeView.Nodes

    .Add StrParent, tvwChild, StrChild, StrChild

    End With

    End If

    Rst.MoveNext

    Loop

    ' adds images to the nodes

    Dim Nds As Nodes
    Dim Nd As Node

    Set Nds = MyTreeView.Nodes


    For Each Nd In Nds

    If Nd.Child = Null Then ' if child node then add red square

    Nd.Image = "img3"


    ElseIf Nd.Expanded = True Then

    Nd.Image = "img2" 'if expanded parent then show "-" image


    ElseIf Nd.Expanded = False Then

    Nd.Image = "img1" ' if collapsed node then show "+" image

    End If



    Next Nd


    Set Rst = Nothing
    Set DB = Nothing

    End Sub

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    How is MyTreeView declared? Is it a control or ActivX Control on your Form?

  3. #3
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    I mean, is it MS TreeView Control version 5 or 6?

  4. #4
    Join Date
    Feb 2004
    Location
    London
    Posts
    46
    I can't see that it is. Think it just works as an activex client as the only bit of code in the example seems to be to expand/add/update the tree.

    I'll attach the example that i'm butchering:
    Attached Files Attached Files

  5. #5
    Join Date
    Feb 2004
    Location
    London
    Posts
    46
    sorry matey

    think it maybe two? the class is MSComctlLib.TreeCtrl.2

  6. #6
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    I opend your mdb file and it functions by me without any problem. Even the you cann add new node.

  7. #7
    Join Date
    Feb 2004
    Location
    London
    Posts
    46
    oh no sorry, didn't explain too well.

    That's the example i'm using. Here's a chopped down one (sorry had to take out load of company / employee information etc) but this replicates the error if you run the frmMainForm.

    Need to put something (e.g. s01943) in the User ID but thats where I was gonna pull the query criteria from

    thanks
    Attached Files Attached Files

  8. #8
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Just try it now.
    Hope that's what you need
    Attached Files Attached Files

  9. #9
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    The trick was just creating a temp table, having the informatin needed from yur query, also the text box of the userID must not be empty

  10. #10
    Join Date
    Feb 2004
    Location
    London
    Posts
    46
    that works great! thanks very much for your help!! much appricated, was driving me crazy hehe

    So was it that (other than the textbox being blank) that it needs to function off a table rather than a query? I noticed your EOF code in there - was that was couldn't function out of the query. Sorry for the questions just interested

  11. #11
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    No, problem for the question:
    The EOF check is needed if the table zz i.e your query results in no records. So you can not move to the first record.

  12. #12
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    I have a question to you too,
    I use mainly ACCE$$97, I tried to convert it to 97 but it doesn't function. Do you know what should I add or use in order to get it run under ACCESS97 too?

  13. #13
    Join Date
    Feb 2004
    Location
    London
    Posts
    46
    Thanks mate, makes some sense now

    I believe access only converts forward and not backwards. As a company we had been using access 97 for years and sometimes it's important to revert back to the 97 version. I've found a credible (but ambiguous) solution is to create 97 db and then copy and paste the tables and so on into it

    Hope that's of help, again thanks so much for your help, saved me HOURS

  14. #14
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    I converted your DB to 97 version, it runs but it doesn't show the nodes

  15. #15
    Join Date
    Feb 2004
    Location
    London
    Posts
    46
    hmm ok.

    Try this.. might not work.. but I used access 2000's "covert to a prior version" tool. Gave some stupid error message that we had some library missing but did it anyway.. so it might not work

    If not it might just be a class (the treeview version) that is in access 2000 though I'd just be guessing at that
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •