Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access 通过循环值并跳过空格,将多行插入Access数据库_Ms Access_Vba - Fatal编程技术网

Ms access 通过循环值并跳过空格,将多行插入Access数据库

Ms access 通过循环值并跳过空格,将多行插入Access数据库,ms-access,vba,Ms Access,Vba,我正在尝试循环浏览表单上的一系列组合框,跳过空格,然后将它们添加到数据库中,但似乎失败了——知道我该怎么做吗 For i = 1 To 8 If Not (("cboOption" & i).Value = "") Then StrSQL = "INSERT INTO db (mID, uID) VALUES (("cboOption" & i).Value = "", StudentID.Value);" DoCmd.SetWarning

我正在尝试循环浏览表单上的一系列组合框,跳过空格,然后将它们添加到数据库中,但似乎失败了——知道我该怎么做吗

For i = 1 To 8
    If Not (("cboOption" & i).Value = "") Then
        StrSQL = "INSERT INTO db (mID, uID) VALUES (("cboOption" & i).Value = "", StudentID.Value);"
        DoCmd.SetWarnings False
        DoCmd.RunSQL StrSQL
        DoCmd.SetWarnings True
    End If
Next

嗯,我不是100%确定,但是您的代码可能会抛出一个方法或数据未被识别的错误。无论如何,下面的代码应该对其进行排序

For i = 1 To 8
    If Len(Me.Controls("cboOption" & i).Value & vbNullString) <> 0 Then
        StrSQL = "INSERT INTO db (mID, uID) VALUES (" & _
                  Me.Controls("cboOption" & i).Value & ", " & _
                  StudentID.Value & ");"
        DoCmd.SetWarnings False
        DoCmd.RunSQL StrSQL
        DoCmd.SetWarnings True
    End If
Next
        StrSQL = "INSERT INTO db (mID, uID) VALUES ('" & _
                  Me.Controls("cboOption" & i).Value & "', " & _
                  StudentID.Value & ");"