Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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 VBA中为指定列插入查询时出现错误“;3061";-参数太少_Ms Access_Vba - Fatal编程技术网

Ms access 在Access VBA中为指定列插入查询时出现错误“;3061";-参数太少

Ms access 在Access VBA中为指定列插入查询时出现错误“;3061";-参数太少,ms-access,vba,Ms Access,Vba,我试图将一个字段添加到一个字段中,然后在VBA中仅向该特定字段插入值。它抛出一个错误:错误3061-参数太少 下面是使用的代码和查询 Public Sub Yearanddate() Dim strsql As String Dim curnt_yearanddate As Variant Dim curnt_year As Variant Dim curnt_month As Variant curnt_yearanddate = Date Debug.Print curnt_yearandd

我试图将一个字段添加到一个字段中,然后在VBA中仅向该特定字段插入值。它抛出一个错误:错误3061-参数太少

下面是使用的代码和查询

Public Sub Yearanddate()
Dim strsql As String
Dim curnt_yearanddate As Variant
Dim curnt_year As Variant
Dim curnt_month As Variant
curnt_yearanddate = Date
Debug.Print curnt_yearanddate
curnt_year = Year(curnt_yearanddate)
curnt_month = month(curnt_yearanddate)


If (curnt_month = 5) Then
Debug.Print CreateCSField("tblmayscores", "ControlShipping") # this is working fine/creates field

strsql = "INSERT INTO tblmayscores(ControlShipping )SELECT Count([Control Shipping Summary Report].[Supplier DUNS Code]) AS [CountOfSupplier DUNS Code]FROM [Control Shipping Summary Report] INNER JOIN tblmayscores ON [Control Shipping Summary Report].[Supplier DUNS Code] = tblmayscores.[Supplier DUNS] WHERE ((([Control Shipping Summary Report].YearofProblemcaseNumber)= curnt_year) AND (([Control Shipping Summary Report].MonthofProblemcaseNumber)= curnt_month)) OR ((([Control Shipping Summary Report].YearofProblemcaseNumber)= curnt_year-1)) GROUP BY [Control Shipping Summary Report].[Supplier Location Code]"

CurrentDb.Execute strsql
End If

Debug.Print month(curnt_yearanddate)
End Sub

我认为不能在“Insert-in”语句中使用“groupby”。我还认为最好避免在Insert Into语句中使用联接。为什么需要动态创建字段?这是一种“代码气味”。我怀疑你在几年或几个月内都在添加列/字段,这绝不是一个好主意!
tblmayscores
中是否有其他字段(假设已经存在)?如果手动复制SQL并在access中运行,SQL是否工作?如果没有,请仔细检查字段名是否正确。请将SQL语句分成若干位,然后一起引用它们。这将更容易定位错误,并且在将来需要更改时更容易处理。