0

我已经尝试并试图让这段代码正常工作,但没有运气。

该代码应该选择与 cmbsource 具有相同产品代码部分的产品。

Private Sub cmbSource_AfterUpdate()

Dim Worktop As String

If ProductType = 1 Then

Worktop = "SELECT [products/stock].[Product Code], [products/stock].Description, [products/stock].[Stock Level] FROM [products/stock] " & _
"WHERE Category = 'DPALRC' " & _
"AND Mid('[Product Code]',1,5) = Mid('" & Me.cmbSource.Value & "',1,5) " & _
"AND Mid('[Product Code]',9,6) = Mid('" & Me.cmbSource.Value & "',9,6) " & _
"ORDER BY [Product Code];"

Me.cmbResult.rowSource = Worktop
Me.cmbResult = vbNullString

End If

有任何想法吗?

在此先感谢,鲍勃 P

4

2 回答 2

1

这里只是一个疯狂的猜测。

Worktop = "SELECT ps.[Product Code], ps.Description, ps.[Stock Level]" & vbCrLf & _
"FROM [products/stock] AS ps" & vbCrLf & _
"WHERE ps.Category = 'DPALRC'" & vbCrLf & _
"AND Mid([Product Code],1,5) = '" & Mid(Me.cmbSource,1,5) & "'" & vbCrLf & _
"AND Mid([Product Code],9,6) = '" & Mid(Me.cmbSource,9,6) & "'" & vbCrLf & _
"ORDER BY ps.[Product Code];"
Debug.Print Worktop

转到立即窗口 ( Ctrl+g) 并从那里复制语句。然后创建一个新的 Access 查询,切换到 SQL 视图,粘贴语句文本并运行它。

如果我建议的代码没有返回您想要的结果,请向我们展示实际的 SQL 语句文本并解释它有什么问题。

于 2012-10-03T17:29:04.113 回答
0
Worktop = "SELECT [products/stock].[Product Code], [products/stock].Description, [products/stock].[Stock Level] FROM [products/stock] " & _
"WHERE Category = 'DPALRC' " & _
"AND Mid([Product Code],1,5) = Mid('" & Me.cmbSource.Value & "',1,5) " & _
"AND Mid([Product Code],9,6) = Mid('" & Me.cmbSource.Value & "',9,6) " & _
"ORDER BY [Product Code];"

这是我的更新版本,原来编码中唯一的错误是在[Product Code].

于 2012-10-05T07:32:24.157 回答