Treeview in Access

silentwolf

Well-known Member
Joined
May 14, 2008
Messages
1,216
Office Version
  1. 2016
Hi guys,
Just wondering if someone can tell me what I do wrong with my treeview control.
Situation:
I have a treeview control (tvwKundenRechnung) two textboxes txtKunden and txtRechnung two subforms subfrmKunde and subfrmRechnung.

CustomerId is the parent node of my treeview control. And the Invoices (Rechnungen) is the child.

When I select the invoice number the value (Rech_id) gets displayed in txtRechnung and that textbox is linked with my subfrmRechnung to show all relevant Information about the Rechnung (Invoice). That works fine!

But the problem is when I select the CustomerId in my txtKunde there is enName=101 displayed rather then only the customerId so "101"

That means that the subfrmCustomer gets displayed but with all empty fields :( ,
When I do write in the txtKunden the number 101 then the subfrmKunden displayes all relevant customer Information.

So I am wondering what the problem is and how I could fix it?

Here is the code I use and maybe someone could take a look at it for me please.

Code:
Private Sub CreateCustomerNodes()
  Dim rst As DAO.Recordset ' recordset for category data
  
  ' open the recordset for categories
  Set rst = CurrentDb.TableDefs!tblKunde.OpenRecordset
   
  ' loop through the rows in the recordset
  rst.MoveFirst
  Do Until rst.EOF
    With Me.tvwKundenRechnung.Nodes.Add(Text:=rst!Kun_id, _
      Key:="FirmenName=" & CStr(rst!Kun_id))
            .Expanded = True
    End With
          
    rst.MoveNext
  Loop
'  rst.Close
'  Set rst = Nothing
End Sub

Private Sub CreateBillNodes()
  Dim rst As DAO.Recordset ' recordset for product data

  ' open the recordset for products
  Set rst = CurrentDb.TableDefs!tblRechnung.OpenRecordset

  ' loop through the rows in the recordset
  rst.MoveFirst
  Do Until rst.EOF
    Me.tvwKundenRechnung.Nodes.Add Relationship:=tvwChild, _
        Relative:="FirmenName=" & CStr(rst!Kun_id_f), _
        Text:=rst!RechNummer, Key:="Rech=" & CStr(rst!Rech_id)
                
    rst.MoveNext
  Loop
'  rst.Close
'  Set rst = Nothing
End Sub

Private Sub cmdCollapseAll_Click()
  Dim nodthis As MSComctlLib.Node
  For Each nodthis In Me.tvwKundenRechnung.Nodes ' loop through all nodes
    nodthis.Expanded = False
  Next nodthis
  Me.tvwKundenRechnung.SetFocus
End Sub

Private Sub cmdExpandAll_Click()
  Dim nodthis As MSComctlLib.Node
  For Each nodthis In Me.tvwKundenRechnung.Nodes ' loop through all nodes
    nodthis.Expanded = True
  Next nodthis
  With Me.tvwKundenRechnung
    .SetFocus ' move focus back to the treeview

    ' make sure the selected item is back into the visible part of the treeview
    .SelectedItem.EnsureVisible
  End With
End Sub

Private Sub Form_Open(Cancel As Integer)
  SetupTreeview
  CreateCustomerNodes
  CreateBillNodes
End Sub

Private Sub SetupTreeview()
  With Me.tvwKundenRechnung
    .Style = tvwTreelinesPlusMinusText
    .LineStyle = tvwRootLines
    .Indentation = 240
    .Appearance = ccFlat
    .HideSelection = False
    .BorderStyle = ccFixedSingle
    .HotTracking = True
    .FullRowSelect = True
    .Checkboxes = False
    .SingleSel = False
    .Sorted = False
    .Scroll = True
    .LabelEdit = tvwManual
    .Font.Name = "Verdana"
    .Font.Size = 9
  End With
End Sub

Private Sub tvwKundenRechnung_Click()
    Dim nodSelected As MSComctlLib.Node ' a variable for the currently selected node
    
    Set nodSelected = Me.tvwKundenRechnung.SelectedItem ' get the currently selected node
    
    If nodSelected.Key Like "Rech=*" Then ' are we on a bill node
        Me.txtRechnung = Mid(nodSelected.Key, 6)
        Me.subfrmRechnung.Visible = True
        Me.txtKunden = Null
        Me.subfrmKunde.Visible = False
    ElseIf nodSelected.Key Like "FirmenName=*" Then ' are we on a customer node
        Me.txtKunden = Mid(nodSelected.Key, 5)
        Me.subfrmKunde.Visible = True
        Me.txtRechnung = Null
        Me.subfrmRechnung.Visible = False
    Else ' somehow this is neither a customer or bill node
        Me.txtRechnung = Null
        Me.subfrmRechnung.Visible = False
        Me.txtKunden = Null
        Me.subfrmKunde.Visible = False
    End If
    
End Sub
Would be nice if someone knows what am I doing wrong here.

Many thanks
Albert
 
Norie,
yes I do understand that but in my case there are projects, invoices, phonenumbers, orders, references and so forth just for the customers.
Now where I do not know how to set it up is what do I do or how do I get all those informations into forms.
Oh it should mean tabcontrol I think in english.
So with tags.... One customer second Projects and so on...
I always turn in circles to get this database somehow finished :(
The structure I believe is ok but with all the linkes I get more than confused I mean to be able to have it all working.
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Albert

Why do you need all this information on one form?

Couldn't you have a main form which gives details of the customer and has buttons that will open other forms?

Each of these forms could be used to display a particular set of data, eg Projects, Invoices etc. for a customer.

So on the main form the user selects the customer they are interested in, clicks the Invoices button and a form opens with all there invoices.

They can then view/add/edit/delete invoices and once finished close the invoice form and return to the main form.

I don't know if this sounds complicated but I don't think it is and it's quite easy to set up.
 
Upvote 0
Norie,
ok so I set up a main form... what would I have on this form?
Customers, projects, Suplier, and so on..
Would then if I click on those open the main form so to speak for the customer.
And then have those customer form several buttons to open other forms?
Well it is a little complex for me the hole structure and as soon I start putting it all together I loose track on it.
For example has the CutomerId about 10 other tables which is linked to.
Hope I am not frustrading you??
 
Upvote 0
What tables are linked to the customer table?
 
Upvote 0
ok,
tblCustomerTyp, tblReference, tblOffers, tblCustTelefon, tblCustomerGroup, tblInvoices, tblCorrespondence, tblProjects, and I guess some more.
But the problem is also that some of those tbles are many to many so the tables are again linked to others.
And that is where all gets a bit messy :(
 
Upvote 0
How many customer types to you have?

How many phone numbers does the average customer have?

Are any of these tables linked with each other?

eg tblInvoices and tblCorrespondence
 
Upvote 0
well the everage phone numbers are not that many but some of the clients can have different offices or homes or businesses where they have other contact numbers.
tblCustomerTyp to tblCustomer (1 to Many)
tblReference to tblCustomer (1 to Many)
tblCustomer to tblOffer (1 to Many)
tblOffer to tblOfferPreis (1 to Many)
tblOfferPreis to tblPreisList (Many to 1) so it is linked but the other way around. Hope you can understand what I am writing here??
tblPreisList to tblUnits (Many to 1)
that is a small part of the structure.. Just like to send this to you so you can tell me if you can understand this?
 
Upvote 0
Albert

You've got my email I think so you can send it if you want.

If you can't find it I can send you a PM.
 
Upvote 0

Forum statistics

Threads
1,215,055
Messages
6,122,902
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top