you must use the same number of fields when you set the LinkChildsFields...

Darth Vodka

Registered User.
Local time
Today, 15:34
Joined
Sep 25, 2007
Messages
344
aaah

error 2335 in this code:-

Code:
Sub FormatGrid(strType As String)
    Dim strHeaders(1)           As String
    Dim strSourceObjects(1)     As String
    Dim strChildLink            As String
    Dim strMasterLink           As String
    Const GUITABLE              As String = "tbl_Static_GridGui"
    
    strHeaders(0) = Nz(DLookup("Header1", GUITABLE, "GridHeader='" & strType & "'"), "")
    strHeaders(1) = Nz(DLookup("Header2", GUITABLE, "GridHeader='" & strType & "'"), "")
    strSourceObjects(0) = Nz(DLookup("Source1", GUITABLE, "GridHeader='" & strType & "'"), "")
    strSourceObjects(1) = Nz(DLookup("Source2", GUITABLE, "GridHeader='" & strType & "'"), "")
    strChildLink = Nz(DLookup("ChildFields", GUITABLE, "GridHeader='" & strType & "'"), "")
    strMasterLink = Nz(DLookup("MasterFields", GUITABLE, "GridHeader='" & strType & "'"), "")
    
    Me.Controls("lblGrid1").Caption = strHeaders(0)
    Me.Controls("lblGrid1").Visible = True
    Me.Controls("chlGrid1").SourceObject = strSourceObjects(0)
    Me.Controls("chlGrid1").LinkChildFields = strChildLink
    Me.Controls("chlGrid1").LinkChildFields = strMasterLink
    Me.Controls("chlGrid1").Visible = True

End Sub

it seems when you assign a new sourceobject it resets the childlink & master link to one field

:mad::mad::mad:

anyone had this before and kow how to get around it?
 
Me.Controls("chlGrid1").LinkChildFields = strChildLink
Me.Controls("chlGrid1").LinkChildFields = strMasterLink
is this right?
 
ha, i;ve solved it

the changing of the source object means that it guesses the linkage and it always guesses a one-field link and it doesn't let you change one side of the link to two fields if the other is one

but

you can raze them and then change them

so

Code:
Sub FormatGrid(strType As String)
    Dim strHeaders(1)           As String
    Dim strSourceObjects(1)     As String
    Dim strChildLink            As String
    Dim strMasterLink           As String
    Const GUITABLE              As String = "tbl_Static_GridGui"
    
    strHeaders(0) = Nz(DLookup("Header1", GUITABLE, "GridHeader='" & strType & "'"), "")
    strHeaders(1) = Nz(DLookup("Header2", GUITABLE, "GridHeader='" & strType & "'"), "")
    strSourceObjects(0) = Nz(DLookup("Source1", GUITABLE, "GridHeader='" & strType & "'"), "")
    strSourceObjects(1) = Nz(DLookup("Source2", GUITABLE, "GridHeader='" & strType & "'"), "")
    strChildLink = Nz(DLookup("ChildFields", GUITABLE, "GridHeader='" & strType & "'"), "")
    strMasterLink = Nz(DLookup("MasterFields", GUITABLE, "GridHeader='" & strType & "'"), "")
    
    Me.Controls("lblGrid1").Caption = strHeaders(0)
    Me.Controls("lblGrid1").Visible = True
    Me.Controls("chlGrid1").SourceObject = strSourceObjects(0)
    Me.Controls("chlGrid1").LinkChildFields = ""
    Me.Controls("chlGrid1").LinkMasterFields = ""
    Me.Controls("chlGrid1").LinkChildFields = strChildLink
    Me.Controls("chlGrid1").LinkMasterFields = strMasterLink
    Me.Controls("chlGrid1").Visible = True

End Sub

works

funny how you come in on a morning and solve something straight away when i spent 30 minutes banging my head about it late yesterday

:D
 
Simple Software Solutions

Not wishing to sound condesending, but I thought that performing as series of DLookUps on the same table with the same criterion is a bit labour intensive. Would it not be more efficient to use a recordset, such as

Dim Rs As Recordset

Set Rs = CurrentDb("Select * From tbl_Static_GridGui Where GridHeader='" & strType & "'")

If Not Rs.EOF Then
Me.lblGrid.Caption = Rs("Header1")
Me.lblGrid.Visible = True
Me.chlGrid1.LinkChildFields = Rs("ChildFields")
Me.chlGrid1.LinkMasterFields = Rs("MasterFields")
etc.
etc.
End If

Rs.Close
Set Rs = Nothing

Using this technique you would only need to vist the table once.

Just a suggestion.

CodeMaster::cool:
 
Not wishing to sound condesending, but I thought that performing as series of DLookUps on the same table with the same criterion is a bit labour intensive. Would it not be more efficient to use a recordset, such as

no, fair call: it's not condescending, it's constructive criticism ;)

it's a trade off between less lines and less calls: i prefer the odd dlookup instead of all the bumf of the obect variable

maybe having so many dlookups would mean switching to recordset...i kind of started with two and it kept growing

ta
 
Code:
    Me.Controls("chlGrid1").LinkChildFields = ""
    Me.Controls("chlGrid1").LinkMasterFields = ""
    Me.Controls("chlGrid1").LinkChildFields = strChildLink
    Me.Controls("chlGrid1").LinkMasterFields = strMasterLink

Almost 5 years apart yet thank you so very much, this really is solved my problem :)
(I have the same problem)
 

Users who are viewing this thread

Back
Top Bottom