Try passing OpenArgs to form
Pan,
This may work for you.
Pass an OpenArgs argument in your open form statement, with a delimeted list of the fields the user has selected.
In the target form's Load event, parse the OpenArgs, and show the columns specified in the OpenArgs, and hide the others.
On the selection Form, for the Click event of the OK button...
Private Sub cmdOK_Click()
Dim szOpenArgs As String
Dim varItem As Variant
Dim ctl As Control
Set ctl = Me.lstFieldSelector
If ctl.ItemsSelected.Count > 0 Then
szOpenArgs = "/"
For Each varItem In ctl.ItemsSelected
szOpenArgs = szOpenArgs & ctl.ItemData(varItem) & "/"
Next varItem
End If
Set ctl = Nothing
'Open the form passing the delimeted string housing the required column selection
DoCmd.OpenForm "frmMyDisplayForm", acFormDS, , , _
acFormPropertySettings, acWindowNormal, szOpenArgs
'Close the form used for the selection process (me)
DoCmd.Close acForm, Me.Name
End Sub
Then in the Load event of the target form...
Private Sub Form_Load()
'if none specified, or no OpenArgs supplied, then don't hide any (show all)
If Len(Nz(Me.OpenArgs)) > 0 Then
ManageColumn "/fruit/", Me.txtFruit
ManageColumn "/weekday/", Me.txtWeekday
ManageColumn "/relationship/", Me.txtRelationship
ManageColumn "/colour/", Me.txtColour
ManageColumn "/pet/", Me.txtPet
Else
Me.txtFruit.ColumnHidden = False
Me.txtWeekday.ColumnHidden = False
Me.txtRelationship.ColumnHidden = False
Me.txtColour.ColumnHidden = False
Me.txtPet.ColumnHidden = False
End If
End Sub
Private Sub ManageColumn(szSearchFor As String, ctl As Control)
If Not InStr(1, Me.OpenArgs, szSearchFor, vbTextCompare) > 0 Then
ctl.ColumnHidden = True
Else
ctl.ColumnHidden = False
End If
End Sub
Here's my P.O.C DB (access 97)
Hope This Helps
Regards
John.