我正在使用Access 2007数据库并且我已经设置了DAO记录集查询,但是它没有返回任何结果。它没有抛出任何错误,只是没有结果。 Me.ProID是一个文本字段,它包含字母和数字。我认为它与文本字段有关,可能是引用的位置。
Dim contractSQL As String
Dim contractDB As DAO.Database
Dim contractRS As DAO.Recordset
contractSQL = "SELECT Top 1 ContractName, ItemDescription, Price FROM ContractPricing WHERE AccountNo = " & Me.Parent.[AccntNumber] & " AND PartNo = " & """ & Me.ProdID & """ & " ORDER BY Price Asc"
Set contractDB = CurrentDb
Set contractRS = contractDB.OpenRecordset(contractSQL)
Debug.Print contractRS.RecordCount
答案 0 :(得分:1)
字符串连接可能是错误的。 " & """ & Me.ProdID & """ & "
几乎肯定是'" & Me.ProdID & "'
答案 1 :(得分:0)
我不知道你是指这个:
contractSQL = "SELECT Top 1 ContractName, ItemDescription, Price FROM ContractPricing WHERE AccountNo = " & Me.Parent.[AccntNumber] & " AND PartNo = " & Me.ProdID & " ORDER BY Price Asc"
我不确定这是否会对你有所帮助。我也是新手。但希望它会。