VB里的日期语法错误,在查询表达式****
错误提示如图所示代码如下:PrivateSubcmdOK_Click()IfcboType.Text="分类汇总"Thensql="SELECT库存表.商品名称,Sum(...
错误提示如图所示
代码如下:
Private Sub cmdOK_Click() If cboType.Text = "分类汇总" Then sql = "SELECT 库存表.商品名称, Sum(销售单.count) AS 销量合计, 销售单.type, 销售单.price From 库存表 INNER JOIN 销售单 ON 库存表.商品编号 = 销售单.code GROUP BY 库存表.商品名称, 销售单.outdate, 销售单.type, 销售单.price HAVING 库存表.商品名称='" & cboName.Text & "' AND 销售单.outdate Between #" & DTStar.Value & "# And #" & DTEnd.Value & "# ORDER BY 销售单.outdate" Set RS = Db.OpenRecordset(sql) Search Exit Sub End If If cboType.Text = "查询明细" Then sql = "SELECT 库存表.商品名称, 销售单.count, 销售单.type, 销售单.price FROM 库存表 INNER JOIN 销售单 ON 库存表.商品编号 = 销售单.code WHERE 库存表.商品名称='" & cboName.Text & "' AND 销售单.outdate Between #" & DTStar.Value & "# And #" & DTEnd.Value & "#" Set RS = Db.OpenRecordset(sql) Search Exit Sub End IfMsgBox "请先设定查询的条件"End Sub 展开
代码如下:
Private Sub cmdOK_Click() If cboType.Text = "分类汇总" Then sql = "SELECT 库存表.商品名称, Sum(销售单.count) AS 销量合计, 销售单.type, 销售单.price From 库存表 INNER JOIN 销售单 ON 库存表.商品编号 = 销售单.code GROUP BY 库存表.商品名称, 销售单.outdate, 销售单.type, 销售单.price HAVING 库存表.商品名称='" & cboName.Text & "' AND 销售单.outdate Between #" & DTStar.Value & "# And #" & DTEnd.Value & "# ORDER BY 销售单.outdate" Set RS = Db.OpenRecordset(sql) Search Exit Sub End If If cboType.Text = "查询明细" Then sql = "SELECT 库存表.商品名称, 销售单.count, 销售单.type, 销售单.price FROM 库存表 INNER JOIN 销售单 ON 库存表.商品编号 = 销售单.code WHERE 库存表.商品名称='" & cboName.Text & "' AND 销售单.outdate Between #" & DTStar.Value & "# And #" & DTEnd.Value & "#" Set RS = Db.OpenRecordset(sql) Search Exit Sub End IfMsgBox "请先设定查询的条件"End Sub 展开
2个回答
2015-04-28
展开全部
format(DTStar.Value,"yyyy-mm-dd")
DTEnd.Value 也如此 错误提示都显示 星期一了。
DTEnd.Value 也如此 错误提示都显示 星期一了。
更多追问追答
追问
敢问,这句代码写在哪个位置呢?我现在脑袋一片浆糊!
追答
Private Sub cmdOK_Click()
If cboType.Text = "分类汇总" Then
sql = "SELECT 库存表.商品名称, Sum(销售单.count) AS 销量合计, 销售单.type, 销售单.price
From 库存表 INNER JOIN 销售单 ON 库存表.商品编号 = 销售单.code GROUP BY 库存表.商品名称,
销售单.outdate, 销售单.type, 销售单.price HAVING 库存表.商品名称='" & cboName.Text
& "' AND 销售单.outdate Between #" & format(DTStar.Value,"yyyy-mm-dd") & "# And #"
& format(DTEnd.Value,"yyyy-mm-dd") & "# ORDER BY 销售单.outdate"
Set RS = Db.OpenRecordset(sql)
Search
Exit Sub
End If
If cboType.Text = "查询明细" Then
sql = "SELECT 库存表.商品名称, 销售单.count, 销售单.type, 销售单.price FROM 库存表 INNER
JOIN 销售单 ON 库存表.商品编号 = 销售单.code WHERE 库存表.商品名称='" & cboName.Text
& "' AND 销售单.outdate Between #" & format(DTStar.Value,"yyyy-mm-dd") & "# And #"
& format(DTEnd.Value,"yyyy-mm-dd") & "#"
Set RS = Db.OpenRecordset(sql)
Search
Exit Sub
End If
MsgBox "请先设定查询的条件"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询