嵌套循环以从/从2个组合框迭代值 [英] Nested loop to Iterate Values from/of 2 combo boxes

查看:78
本文介绍了嵌套循环以从/从2个组合框迭代值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立大学入学管理系统;有2个名为类别和组的表.

I am making a College Admission Management System; there are 2 tables named Categories and Groups.

该类别包含一个名为Category的字段,其中包含诸如陆军服务",Army Retired, Civilian等值.而Groups Table则具有一个名为Group的字段,其中包含诸如Pre-Engineering, Pre-Medical等值.

The category contains a field named Category which contains values like 'Army Serving' , Army Retired, Civilian , etc.. while Groups Table has a field named Group that contains values such as Pre-Engineering, Pre-Medical etc..

通过从表单的组合框中选择类别和组,我可以成功地分别预览所有列表,并且还可以创建具有所需分数才能被录取的学生功绩列表.

I am successfully able to preview all lists separately by selecting the category and group from combo boxes in a form, and I am also able to create a Merit list of students that have the required marks to get admitted.

现在,我想自动化它,就像'Generate All''Create All'按钮一样,它将根据类别和组生成所有优点列表.

Now, I want to automate it, like a 'Generate All' and 'Create All' Button that would generate all Merit Lists according to their category and Group.

在这里:GroupVal是Group ComboBox的名称,而QuotaVal是Category ComboBox的名称.

Here: GroupVal is the name of Group ComboBox and QuotaVal is the name of Category ComboBox.

我尝试了这段代码,但是每次我修复一个错误时,它都会返回不同的错误.

I tried this code but it returns different errors every single time I fix one error.

Private Sub CreateAllKey_Click()

Dim QuotaList As String
Dim GroupList As String
Set QuotaList = Tables!Categories!Category
Set GroupList = Tables!Groups!Group
For Each QuotaList In QuotaVal
    For Each GroupList In GroupVal
        DoCmd.OpenQuery "Merit List Generator", acViewNormal, acEdit
    Next
Next

MsgBox "All Lists Successfully Cleated", vbOKOnly, "Merit List Created!"

End Sub

下面的代码仅返回1个值..意味着,它仅在一个值上运行,并且仅给出1个值;

And this following Code is returning only 1 value.. means, it runs on one value only and give out only 1 value;


    Dim QuotaList As Integer
    Dim GroupList As Integer

    For QuotaList = 0 To Me.QuotaVal.ListCount - 1
        If QuotaList = 0 Then
            Me.QuotaVal.Value = "AR"
        End If
        If QuotaList = 1 Then
            Me.QuotaVal.Value = "AS"
        End If
        If QuotaList = 2 Then
            Me.QuotaVal.Value = Null
        End If
        If QuotaList = 3 Then
            Me.QuotaVal.Value = "DP"
        End If
        If QuotaList = 4 Then
            Me.QuotaVal.Value = "FGEI"
        End If
        If QuotaList = 5 Then
            Me.QuotaVal.Value = "RFGEI"
        End If
        For GroupList = 0 To Me.GroupVal.ListCount - 1
            If GroupList = 0 Then
                Me.GroupVal.Value = "Gen-Sci-I"
            End If
            If GroupList = 1 Then
                Me.GroupVal.Value = "Gen-Sci-II"
            End If
            If GroupList = 2 Then
                Me.GroupVal.Value = "Gen-Sci-III"
            End If
            If GroupList = 3 Then
                Me.GroupVal.Value = "Humanities"
            End If
            If GroupList = 4 Then
                Me.GroupVal.Value = "Pre-Engg"
            End If
            If GroupList = 5 Then
                Me.GroupVal.Value = "Pre-Med"
            End If
            DoCmd.OpenQuery ("Merit List Creator")
        Next
    Next

End Sub

例如;我想要这样的东西:

For example; I want something like this:

'Create lists of numbers and letters
Dim numbers() As Integer = {1, 4, 7}
Dim letters() As String = {"a", "b", "c"}

'Iterate through the list by using nested loops.
For Each number As Integer In numbers
    For Each letter As String In letters
        Debug.Write(number.ToString & letter & " ")
    Next
Next
Debug.WriteLine("")
'Output: 1a 1b 1c 4a 4b 4c 7a 7b 7c

在每次选择值而不是打印'1a,1b,1c,4a,4b,••时,将数字的值视为类别表,将字母的值视为组表并运行成绩列表生成器"查询, •'

Consider the values of Numbers as Categories Table here and the value of Alphabets as Groups Table and run the 'Merit List Generator" Query each time it selects values instead of printing '1a, 1b, 1c, 4a, 4b,•••'

请记住,所有查询公式都是正确的并且可以正常工作.当我输入自己的类别和组值时生成一个列表时,它们都可以正常工作.

Keep in mind, all query formulas are correct and working.. they are working when I generate a single list when I input my own category and group values.

修复一个或另一个错误后出现的错误是:'Can't Assign Value' 'Object Required' 'Data Mismatch'没有任何作用! 如果有人写过这样的代码,请给我发送...这比纠结的耳机还要复杂. XD

The errors I get after fixing one or the other error are: 'Can't Assign Value' 'Object Required' 'Data Mismatch' Nothing worked! If anyone has written such code, please send me... This is more complex than a tangled earphone. XD

推荐答案

您所描述的内容听起来像笛卡尔查询.当查询缺少JOIN子句时,每个表的每个记录将与其他表的每个记录关联.结果是每对可能的组合.

What you describe sounds like a Cartesian query. When a query lacks a JOIN clause, every record of each table will associate with every record of other table. The result is every possible combination of pairs.

SELECT Category, Group FROM Categories, Groups;

这篇关于嵌套循环以从/从2个组合框迭代值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆