Avatar billede hnteknik Novice
23. december 2003 - 13:24 Der er 10 kommentarer og
1 løsning

AccXP:Subdatasheets vist i en formular ?

jeg har i mange år brugt datarkvisning af et søgeresultat.
Da jeg nu har et søgeresultat, som giver op til flere resultater med samme ID, ville jeg gerne blot vise hovedresultat som en resultatlinie og alle relaterede resultater som subdatasheet.

Jeg har lavet Queryen som flot viser hovedresultatet og valgte subdatasheet, men

Dataarkvisningen i formularen kan tilsyneladende ikke håndtere hierakiske data.


Findes der en ren Access løsning, eller skal jeg over i at installere en 'hierarchical flexgrid control' og lave min Query om efter:

sqlstr = "SHAPE {" & _
"SELECT * " & _
"FROM " & topSource & "} APPEND ({SELECT * " & _
"FROM " & subDS & " } AS rs RELATE " & LinkCF & _
" TO " & LinkMF & ")".

I fald flexgrid controllen er den 'eneste' løsning, findes den så sammen med udviklerdelen til Office XP ?

God Jul Henrik
Avatar billede terry Ekspert
23. december 2003 - 14:47 #1
There isnt a pure Access solution for this and I Office developer doesnt contain this component. There are a couple of grids on the market which are compatible with Access an damny which are not.

The VSFlexgrid (videosoft) works great with Access. I am not sure if this is th esame flexgrid which comes with MS Visual Basic.
Avatar billede terry Ekspert
23. december 2003 - 14:47 #2
an damny  = and many
Avatar billede hnteknik Novice
23. december 2003 - 15:53 #3
Anyway - whats new in Xp besides bugs removed and new introduced.
I better get my old vb6 up from the dustbin.

X-mas to you and everyone
Henrik
Avatar billede terry Ekspert
23. december 2003 - 17:00 #4
"I better get my old vb6 up from the dustbin." :o)

Well for a start there is integration to Visual Source Safe and it is MUCH more stable than 2000 specially when working with ADP/ADE.

Have you not concidered VB.NT?

and a Merry X-Mass to too!
Avatar billede hnteknik Novice
23. december 2003 - 17:43 #5
HM - skulle der mon ikke være en felxgrid i Office XP developer ?
Fandt denne artikel:
'Displaying a Hierarchical FlexGrid on an Access Form -
Microsoft Office 2000 Developer'
Avatar billede terry Ekspert
23. december 2003 - 18:35 #6
I am 99.99% sure that there isnt! I have XP developer and I cant find it, but it may be hidden
Avatar billede terry Ekspert
23. december 2003 - 18:42 #7
can you give me a link to that article, it may be able to give me some information as to where it is?
Avatar billede hnteknik Novice
23. december 2003 - 19:36 #8
>>terry

Have a look a this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odecore/html/decondisplayinghierarchicalflexgridonaccessform.asp

You might be right, but it was included with the 2000 Developer.
Could it be behind the 'com addins' ???

Henrik
Avatar billede terry Ekspert
23. december 2003 - 20:08 #9
Henrik, I have now found the flexgrid but I am still not sure if it comes with XP Developer or something else. I'll try and find out for sure if it does come with XP developer and get back.
Avatar billede terry Ekspert
23. december 2003 - 20:25 #10
Yes its also in XP :o)

The printed manual is terrible and I cant find any mention of these extra controls. This is taken from XP Developer Online Documentation!

Microsoft Office XP Developer Reference 

ModHFGrid ControlSee Also
Properties, Methods, and Events | Calling a Stored Procedure | Issue Tracking Team Solution | ModHFGrid Error Constants | Stored Procedures
The Microsoft® Office XP Developer Hierarchical FlexGrid (ModHFGrid) control displays and operates on tabular data. It makes possible complete flexibility to sort, merge, and format tables containing strings and pictures. When bound to a data control, ModHFGrid displays read-only data.

Syntax

ModHFGrid
Remarks

You can place text, a picture, or both in any cell of a ModHFGrid. The Row and Col properties specify the current cell in a ModHFGrid. You can specify the current cell using code, or the user can change it at run time using the mouse or the arrow keys. The Text property references the contents of the current cell.

If the text in a cell is too long to display in the cell and the WordWrap property is set to True, the text wraps to the next line within the same cell. To display the wrapped text, you might be required to increase the cell's column width (ColWidth property) or row height (RowHeight property).

Use the Col and Row properties to determine the number of columns and rows in a ModHFGrid. Use the Band properties to determine the band styles in ModHFGrid.

Displaying Hierarchical Recordsets
A major feature of the ModHFGrid control is its ability to display hierarchical recordsets — relational tables displayed in a hierarchical fashion. The easiest way to create a hierarchical recordset is to use the Data Environment designer and assign the DataSource property of the ModHFGrid control to the Data Environment. In addition, you can create a hierarchical recordset in code using a Shape command as the RecordSource for an ADO Data Control, as shown in the following example:

' Create a ConnectionString.
Dim strCn As String
strCn = "Provider=MSDataShape.1;Data Source=Nwind;" & _
"Connect Timeout=15;Data Provider=MSDASQL"

' Create a Shape command.
Dim strSh As String
strSh = "SHAPE {SELECT * FROM `Customers`} AS Customers " & _
"APPEND ({SELECT * FROM `Orders`} AS Orders RELATE " & _
"CustomerID TO CustomerID) AS Orders"

' Assign the ConnectionString to an ADO Data Control's
' ConnectionString property, and the Shape command to the
' control's RecordSource property.
With Adodc1
  .ConnectionString = strCn
  .RecordSource = strSh
End With
' Set the HflexGrid control's DataSource property to the
' ADO Data control.
Set HFlexGrid1.DataSource = Adodc1
Avatar billede hnteknik Novice
23. december 2003 - 21:01 #11
Yep found it too and had it up and working - look at my lousy code behind form ( time for x-mas holiday) - some formatting of the grid display is mandatory:

Option Compare Database
Option Explicit


Sub test()
Dim adoxCat As Catalog
'Set a reference for Microsoft ADO Ext. 2.1 (2.7)
'for DDL and security.
Dim cboStr As String, Cancel As Integer
Dim objT As Table, objV As Object
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
Set adoxCat = New ADOX.Catalog
 
 

adoxCat.ActiveConnection = cnn

cboStr = "Table/View Name;Type;"

For Each objT In adoxCat.Tables
  If Left(objT.Name, 4) = "mSys" Or _
    Left(objT.Name, 1) = "~" Then
    GoTo NotATable
  End If

  ' Before adding the table to the ComboBox string, make
  ' sure the table isn't a view as we'll add these later.
  If objT.Type <> "VIEW" Then
    cboStr = cboStr & objT.Name & ";table;"
  End If

NotATable:
  Next objT
 
'Loop through the views to add the queries.
For Each objV In adoxCat.Views
  cboStr = cboStr & objV.Name & ";View;"
Next objV

cboT_V.RowSource = cboStr
'MsgBox cboStr
End Sub

Private Sub Form_Load()
test
End Sub

Sub test2()
Dim topSource As String, subSourceType As String, sourceType As String, subds As String
Dim LinkCF As String, LinkMF As String, a As String
Dim rst As ADODB.Recordset, strConnect As String, sqlstr As String

topSource = Me!cboT_V
If InStr(topSource, " ") Then
  topSource = "[" & topSource & "]"
End If

sourceType = Me!cboT_V.Column(1)

If sourceType = "Table" Then
  subds = tableProperty_FX("SubdatasheetName", topSource)
  LinkCF = klammeom(tableProperty_FX("LinkChildFields", topSource))
  LinkMF = klammeom(tableProperty_FX("LinkMasterFields", topSource))
Else
  subds = QueryProperty_FX("SubdatasheetName", topSource)
  LinkCF = klammeom(QueryProperty_FX("LinkChildFields", topSource))
  LinkMF = klammeom(QueryProperty_FX("LinkMasterFields", topSource))
End If


a = InStr(subds, ".")

subSourceType = Left(subds, a - 1)
subds = klammeom(Right(subds, Len(subds) - a))

Set rst = New ADODB.Recordset
strConnect = CurrentProject.Connection


rst.ActiveConnection = _
  "Provider=MSDataShape;Data " & strConnect
 

sqlstr = "SHAPE {" & _
  "SELECT * " & _
  "FROM " & topSource & "} APPEND ({SELECT * " & _
  "FROM " & subds & " } AS rst RELATE " & LinkMF & _
  " TO " & LinkCF & ")"
 
rst.Open sqlstr
Set MSHFlexGrid.DataSource = rst

rst.Close
Set rst = Nothing

End Sub

Private Sub Kommandoknap0_Click()
test2
End Sub

Function klammeom(strind As String) As String
    If InStr(strind, " ") Or InStr(strind, "-") Then
      strind = "[" & strind & "]"
    End If
    klammeom = strind
End Function

Private Sub Kommandoknap4_Click()
    If cboT_V.Column(1) = "Table" Then
      DoCmd.OpenTable Me!cboT_V, , acReadOnly
    Else
      DoCmd.OpenQuery Me!cboT_V, , acReadOnly
    End If
    SendKeys "%IU"
End Sub
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester