Need help with forms and applyfilter command

W

webvigator2k

I have a database that I've converted from 8 seperate tables into one
cumulative table. instead of having 8 unique tables, there are 8
different tags now (machine1, machine2 etc) that ID every single
record. I've created a form, but i'm having a hard time filtering the
data out (i'm creating 8 seperate forms for each machine which all get
their data from one main table). so basically, i want the machine1
form to only show machine1 data, machine2 form to show machine2 data
etc... this is done through a hidden textbox on the form that holds
the machineID data.

this is the code i've tried to use:

DoCmd.Applyfilter, "[CumulativeSamplesDatabase].[MachineID] =
[Machine1Active]"

the idea of the code above was to only bring up records that have
"machine1active" in the MachineID field.
 
L

Larry Linson

How are you opening the Forms? If from VBA code, you can do one of two
things: Use the WhereCondition argument of DoCmd.OpenForms, or pick up an
SQL string to replace the RecordSource of the Form in the Form's Open Event.
I can't see any need at all to have separate identical Forms, unless you
want to just click them in the Forms tab of the Database window to open the
Form.

Larry Linson
Microsoft Access MVP
 
A

Arno R

8 separate forms is a bad idea... What a PITA if you need to apply changes !

There are several ways in which you can filter the records shown on the form.
'Query by Form' is easy to accomplish.
You need one combo on the 'calling form' (cboMachineID)
cboMachineID rowsource = Machine1; Machine2; Machine 3; ...
Base the form on a query where MachineID = Forms!CallingForm!cboMachineID
 
G

Guest

Eight separate forms is a bit much, you can do the lot quite easily on one form.
You have a field, say Machine, which contains the ID of the machine so create a form which displays all data for all machines.
In the header of the form put either a combo box or, because you only have a few, a frame with the appropriate number of options. This control MUST be unbound & I prefer to colour the header section differently so that the Selection is differentiated from the MachineID in the detail.
In the AfterUpdate event of the combo or the frame do something like

Select case <ControlName> 'cboSelect or fraSelect
Case 0 'All
Me.filter = ""
Me.FilterOn = False
Case 1 'Machine 1
Me.Filter = "[MachineID] = 1" 'Or whatever the ID of machine 1 is
Me.FilterOn = True
Case 2 'Machine 2
Me.Filter = "[MachineID] = 2" 'Or whatever the ID of machine 2 is
Me.FilterOn = True
......
End select

HTH
Terry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top