Skip to main content

AccessTr.neT


Treeviewde Split Form Görüntüsü

Treeviewde Split Form Görüntüsü

#1
Tüm arkadaşlar iyi akşamlar,

Daha önce öğrenmek istediğim tüm sorularıma anında cevap verildiğinden tüm ilgilenenlere teşekkür ederim. Sitenizde sürekli dolaştığımdan treeview uygulamalı bir örnek gördüm ve çok hoşuma gitti. Çok kullanışlı olacağına inandığım için incelemekteyim.

İki sorum olacak müsaadelerinizle;

1 - Treeview uygulamasında Split Form görüntüsü Form görüntüsü şeklinde çıkmaktadır. Tasarım görünümünde Split Form normal çalışıyor fakat Program çalıştığında form görünümüne geçiyor. 

Zannedersem Tables bölümünde bulunan tbl_Switchboard ait kod'a kırmızı olan yere Split Form'a ait bir kod yazmak gerekiyor. Ama siz ustalar daha iyisini bilirsiniz. 


Private Sub tvSB_NodeClick(ByVal node As Object)

   'User clicked a node
   
   Dim strSwitchboard_SubForm_ToShow As String
   Dim strForm_OpenArgs As String
   
   'The default form to be loaded into the subform-area - if no other will be set within this sub
   strSwitchboard_SubForm_ToShow = mconMainForm
   
   'Default: no contents for information being pulled from a form loaded into the subform
   mstrFormArgs = ""
   
   'This statement should actually never evaluate to false, it's rather meant to further
   'describe the usage of the Split()-function
   If UBound(Split(node.Key, ";")) = 3 Then
      Dim strObjectType As String
      Dim strObjectName As String
      Dim strObjectAddtnl As String

      strObjectType = Split(node.Key, ";")(1)   'second argument within the node's key
      strObjectName = Split(node.Key, ";")(2)   'third argument within the node's key
      strObjectAddtnl = Split(node.Key, ";")(3) 'fourth argument within the node's key
      
      On Error Resume Next
      
      Select Case strObjectType
         Case "Form"
            'Just pass on the form's name - this will result in the switchboard's subform
            'being set to this form.
            strSwitchboard_SubForm_ToShow = strObjectName
            mstrFormArgs = strObjectAddtnl
            
         Case "Form_Dialog"
            'Load a form separately
            DoCmd.OpenForm FormName:=strObjectName, windowmode:=acDialog, OpenArgs:=strObjectAddtnl
         
         Case "Report"
            'This is just a sample call to a report - you might want to distinguish
            'between printing directly or showing the preview here.
            DoCmd.OpenReport reportname:=strObjectName ', OpenArgs:=strObjectAddtnl '<-- OpenArgs are possible for reports starting with Access 2002 only!
            
         Case "Code"
            'For the sake of the sample, this call references a sub within the switchboard-form's
            'module (hence the CodeContextObject - this could as well be <Me>).
            'An alternative would be to call a function within a general module - in order to do so,
            'you'll have to know that module's name (or index). The call would then look like this:
            '  CallByName modules(0), strObjectName, VbMethod
            'or
            '  CallByName modules("mdl_SomeModule"), strObjectName, VbMethod
            CallByName CodeContextObject, strObjectName, VbMethod, strObjectAddtnl
            
         Case ""

            'do nothing (user clicked a parent-node)
            
         Case Else
            'Unrecognized "Ojbect-Type" - show an error-message
            MsgBox "Unknown Object-Type within Switchboard-table: " & strObjectType, vbExclamation, "Error"
      End Select
   End If
   
   If Me!Switchboard_Subform.SourceObject <> strSwitchboard_SubForm_ToShow Then
      'If this sub resulted in a different form to be shown in the subform-area, load it
      Me!Switchboard_Subform.SourceObject = strSwitchboard_SubForm_ToShow
   End If

   If Err.Number <> 0 Then
      'For debugging-purposes, I suggest adding a message like this.
      '
      'For the sample, I'm only providing one form
      MsgBox "This would result in a " & strObjectType & " called " & Q & strObjectName & Q & " being called," & vbCrLf & _
         "but calling the object raised an exception (that object probably just doesn't exist).", _
         vbInformation, "Error/bug: (Node-click)"
   End If
   
   If strSwitchboard_SubForm_ToShow <> mconMainForm Then
      'Attempt to have a potentially loaded form refresh its information;
      'In order for this to be successful, the subform will have to provide a public sub called "RefreshInfo"
      Err.Clear
      Switchboard_Subform.Form.RefreshInfo
   End If
End Sub

2 - Bu uygulamada üste bulunan menuleri gizlemek mümkün müdür?

Sorularım çok uzun oldu kusuruma bakmayım. Konuyla ilgilenenlere şimdiden teşekkür ederim.
.rar Personel.rar (Dosya Boyutu: 433,47 KB | İndirme Sayısı: 65)
firtina, 28-05-2009 tarihinden beri AccessTr.neT üyesidir. Hoba
Cevapla
#2
sayın firtina, sorunuzun son durumu nedir acaba?
Cevapla
#3
sayın firtina,

bahsettiğiniz talebinize yönelik olarak;

Frm_Switchboard adlı formun kod sayfasına (ALT + F11) geçiniz ve mevcut tüm kodları aşağıdaki kodlar ile olduğu gibi değiştirerek kullanmayı deneyiniz.

denemeler akabinde kendi adıma olumlu sonuç aldım.

Kod:
Option Compare Database
Option Explicit
'This is usually a globally available constant that I'm using to make including quotes easier
Private Const Q As String * 1 = """"




'This is the name of the default form being displayed in the switchboard's subform if no "real" form
'is being used.
Private Const mconMainForm As String = "Frm_Switchboard_Main"




'This will serve as a means for having a form that is being hosted in the switchboard "pull"
'information from the switchboard using the FormArgs-property
Private mstrFormArgs As String




Public Property Get FormArgs() As String
   FormArgs = mstrFormArgs
End Property




Private Sub Form_Open(Cancel As Integer)
   'Fill TV
   Dim db As DAO.Database
   Dim rs As DAO.Recordset
   Dim strKey As String
   
   
   mstrFormArgs = ""
   
   Set db = CurrentDb
   Set rs = db.OpenRecordset( _
      "SELECT * " & _
      "FROM tbl_Switchboard " & _
      "ORDER BY tbl_Switchboard.SB_Parent, tbl_Switchboard.SB_Order", dbOpenSnapshot, dbReadOnly Or dbForwardOnly)
   
   'Not really required, but - who knows! :-)
   tvSB.nodes.Clear
   
   With rs
      'Loop through all switchboard-items, adding them to the treeview
      While Not .EOF
         'Assemble a key for this node, consisting of three arguments:
         '
         '  1. The ID - required to find a child-node's parent
         '  2. The "Object-type" - form, report, etc.
         '  3. The "Object-Name" - the name of the form, report, etc.
         '  4. Additional stuff (i.e. OpenArgs being passed to a form)
         ' strKey = !SB_ID & ";" & Nz(!SB_ObjectType) & ";" & Nz(!SB_ObjectName) & ";" & Nz(!SB_NodeTitle)
         ' strKey = !SB_ID & ";" & Nz(!SB_ObjectType) & ";" & Nz(!SB_ObjectName) & ";" & Nz(!SB_NodeTitle) & Nz(!SB_Parent)
         strKey = !SB_ID & ";" & Nz(!SB_ObjectType) & ";" & Nz(!SB_ObjectName) & ";" & Nz(!SB_NodeTitle)
         If !SB_Parent > 0 Then
            'This node is a child-node of some other node;
            'Find the parent node and add it below that node's last child
            tvSB.nodes.Add getNodeIndex(!SB_Parent), tvwChild, strKey, !SB_NodeTitle
         Else
            'There is no parent - add this node to the treeview's root
            tvSB.nodes.Add , tvwLast, strKey, !SB_NodeTitle
         End If
         
       
      
         .MoveNext
      Wend
   End With
   
   'Clean up
   Set rs = Nothing
   Set db = Nothing
   
   'initialize the form / show the main form
   Me!Switchboard_Subform.SourceObject = mconMainForm
   
   'Maximize the switchboard
   DoCmd.Maximize
End Sub




Private Sub Form_Resize()
 On Error Resume Next
   Const conBorderDistance As Integer = 100     'Distance of all controls to the form's boundaries
   Const conTV_Width = 3000                     'The width of the treeview (the subform will use the remaining space)
   Const conTV_HeightDeviation As Integer = -5  'The treeview will be slightly higher than an access-control
   
   Painting = False  'This will avoid the form flickernig while being resized
   
   'Reset the controls (in case form is now smaller than before)
   With tvSB
      .Left = 0
      .Top = 0
      .Height = 0
      .Width = 0
   End With
   With Switchboard_Subform
      .Left = 0
      .Top = 0
      .Height = 0
      .Width = 0
   End With
   
   'Adjust detail-section's size
   Me.Section(acDetail).Height = Me.InsideHeight _
      - Me.Section(acFooter).Height - Me.Section(acHeader).Height




   'Reposition the controls
   With tvSB
      .Left = conBorderDistance
      .Width = conTV_Width
      .Top = conBorderDistance
      .Height = Me.Section(acDetail).Height - conBorderDistance * 2
   End With
   
   With Switchboard_Subform
      .Left = tvSB.Left + tvSB.Width + conBorderDistance
      .Width = InsideWidth - tvSB.Width - conBorderDistance * 3
      .Top = conBorderDistance
      .Height = tvSB.Height + conTV_HeightDeviation
   End With
   
   Painting = True
End Sub




Private Sub Form_Unload(Cancel As Integer)
   DoCmd.Restore
   'Show the database-window
   DoCmd.SelectObject acForm, Me.Name, True
End Sub




'Get a node's index from a key-string (being the first of 3 arguments separated by ";")
Private Function getNodeIndex(ByVal strKey As String) As Integer
   Dim intCounter As Integer
   
   'Assume failure (return root)
   getNodeIndex = 0
   
   For intCounter = 1 To tvSB.nodes.Count
      'The key being looked for is the first argument
      If Split(tvSB.nodes(intCounter).Key, ";")(0) = strKey Then
         'Found the node
         getNodeIndex = intCounter
         Exit For
      End If
   Next intCounter
End Function




Private Sub tvSB_NodeClick(ByVal node As Object)
   'User clicked a node
   
   Dim strSwitchboard_SubForm_ToShow As String
   Dim strForm_OpenArgs As String
   
   'The default form to be loaded into the subform-area - if no other will be set within this sub
   strSwitchboard_SubForm_ToShow = mconMainForm
   
   'Default: no contents for information being pulled from a form loaded into the subform
   mstrFormArgs = ""
   
   'This statement should actually never evaluate to false, it's rather meant to further
   'describe the usage of the Split()-function
   If UBound(Split(node.Key, ";")) = 3 Then
      Dim strObjectType As String
      Dim strObjectName As String
      Dim strObjectAddtnl As String




      strObjectType = Split(node.Key, ";")(1)   'second argument within the node's key
      strObjectName = Split(node.Key, ";")(2)   'third argument within the node's key
      strObjectAddtnl = Split(node.Key, ";")(3) 'fourth argument within the node's key
      
      On Error Resume Next
      
      Select Case strObjectType
         Case "Form"
            'Just pass on the form's name - this will result in the switchboard's subform
            'being set to this form.
            strSwitchboard_SubForm_ToShow = strObjectName
            mstrFormArgs = strObjectAddtnl
            
            
         Case "Form_Dialog"
            'Load a form separately
            DoCmd.OpenForm FormName:=strObjectName, windowmode:=acDialog, OpenArgs:=strObjectAddtnl
         
         Case "Report"
            'This is just a sample call to a report - you might want to distinguish
            'between printing directly or showing the preview here.
            DoCmd.OpenReport reportname:=strObjectName ', OpenArgs:=strObjectAddtnl '<-- OpenArgs are possible for reports starting with Access 2002 only!
            
         Case "Code"
            'For the sake of the sample, this call references a sub within the switchboard-form's
            'module (hence the CodeContextObject - this could as well be <Me>).
            'An alternative would be to call a function within a general module - in order to do so,
            'you'll have to know that module's name (or index). The call would then look like this:
            '  CallByName modules(0), strObjectName, VbMethod
            'or
            '  CallByName modules("mdl_SomeModule"), strObjectName, VbMethod
            CallByName CodeContextObject, strObjectName, VbMethod, strObjectAddtnl
            
         Case ""
            'do nothing (user clicked a parent-node)
            
         Case Else
            'Unrecognized "Ojbect-Type" - show an error-message
            MsgBox "Unknown Object-Type within Switchboard-table: " & strObjectType, vbExclamation, "Error"
      End Select
   End If
   
   If Me!Switchboard_Subform.SourceObject <> strSwitchboard_SubForm_ToShow Then
      'If this sub resulted in a different form to be shown in the subform-area, load it
      Me!Switchboard_Subform.SourceObject = strSwitchboard_SubForm_ToShow
   End If




   If Err.Number <> 0 Then
      'For debugging-purposes, I suggest adding a message like this.
      '
      'For the sample, I'm only providing one form
      MsgBox "This would result in a " & strObjectType & " called " & Q & strObjectName & Q & " being called," & vbCrLf & _
         "but calling the object raised an exception (that object probably just doesn't exist).", _
         vbInformation, "Error/bug: (Node-click)"
   End If
   
   If strSwitchboard_SubForm_ToShow <> mconMainForm Then
      'Attempt to have a potentially loaded form refresh its information;
      'In order for this to be successful, the subform will have to provide a public sub called "RefreshInfo"
      Err.Clear
'      Switchboard_Subform.Form.RefreshInfo
   End If
End Sub




'(Sample function being called from a node within the switchboard)
Public Function ShowMessagebox(ByVal strMessageTitle_Suffix As String)
   MsgBox "This is a messagebox being raised by a call issued from a switchboard-node", _
      vbInformation, "Switchboard Sample Database: " & strMessageTitle_Suffix
End Function

bilginize...iyi çalışmalar,saygılar.
Herkes, kendisinin AR-GE'cisidir...


Konulara eklenen Uygulama içeriğine yönelik Tavsiyeler
Alt Form Denetim Değerlerine ulaşma ve Alt Form Güncelleme
Kapatırken Düzenle (Compact On Close) Seçeneğinin İşaretlenmesi Hakkında
Cevapla
#4
Hayırlı cumalar sn. @atoz112
ben kodları yapıştırdım ama olmadı neden olabilir
@benbendedeilem
Cevapla

Bir hesap oluşturun veya yorum yapmak için giriş yapın

Yorum yapmak için üye olmanız gerekiyor

ya da
Task