Passing Field Names between forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a complex 'filter by form' Form with 20+ fields, which having filtered
the records provides the User with a button that opens a switchboard form on
which they choose a Report they wish to see based on the filtered records.

How do I pass the names (not the contents) of the fields used on the 'filter
by form' Form to the switchboard form? I would like to be able to restrict
which Reports are available to Users, based on which fields they have used on
the 'filter by form' Form.

Thanks in anticipation.
 
You can concatenate them, and pass them as the OpenArgs parameter.

Where you're opening the form, you'd do something like:

Dim strFields As String

strField = "Customer;Product;Location"
DoCmd.OpenForm "MyOtherForm", OpenArgs:=strField

(note that you can use any character you like as the concatenation
character. I chose semicolons above)

In the Open or Load event of "MyOtherForm", you'd check whether a OpenArgs
parameter was passed, then use the Split function to break it back into the
individual fields:

Private Sub Form_Load()

Dim varFields As Variant

If IsNull(Me.OpenArgs) = False Then
varFields = Split(Me.OpenArgs, ";")
End If


At this point, varFields(0) would contain Customer, varFields(1) would
contain Product, and varFields(2) would contain Location.
 
Thanks Douglas.

However I realise I didn't explain very well. I need to pass only the names
of the fields to "MyOtherForm" that have been used in the 'filter by form'
Form. How do I pick up these, given that when I apply the filter, the form
will then show records returned with all the fields having data in them.

Thanks in anticipation
 
I suppose you could look at the form's Filter property, and parse out the
names of the fields from it.
 
Back
Top