Question

The purpose of this database is to assign "variable names" to different "tables". We are taking our data and making limited datasets, so I'm using Access to document the process. I have 3 tables:

  • tbl_var - containing all variable information
  • tbl_db - containing the names and characteristics of the limited datasets
  • tbl_vardb - a linking table where a table ID and variable ID are associated

I have created a form to choose which variable to add to a specific dataset. It's very simple with two dropdown boxes. One box is the names of the datasets. The other box is the names of all the variables. The problem is that if I have already selected "sex" as a variable for the "demo" dataset, I do not want "sex" to pop up as an option for future variable drop down values. After all, it's already in the dataset, no reason to add it again. Since there is more than one dataset, hard-coding a dataset name in a query isn't really working for me.

How do I populate the variable dropdown with values that are not already in a specific dataset?

Était-ce utile?

La solution

For the tables [tbl_var] ...

variableID  variableName
----------  ------------
         1  LastName    
         2  FirstName   
         3  Sex         

... [tbl_db] ...

datasetID  datasetName
---------  -----------
        1  Demo       
        2  SomeOther  

... and [tbl_vardb] ...

datasetID  variableID
---------  ----------
        1           3

... if I have a combo box named [cbxDataset] that gets its items from [tbl_db] then I can have another combo box named [cbxVariable] whose Row Source is

SELECT variableID, variableName 
FROM tbl_var 
WHERE variableID NOT IN 
    (
        SELECT variableID 
        FROM tbl_vardb 
        WHERE datasetID=[cbxDataset]
    );

The After Update event of the [cbxDataset] combo box ensures that the other combo box contains the relevant choices

Private Sub cbxDataset_AfterUpdate()
Me.cbxVariable.Requery
End Sub
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top