- Joined
- Apr 6, 2006
- Messages
- 2
- Reaction score
- 0
Hello,
I have a problem assigning a recordset to a listbox when I create it using the Command object. It works OK when I create the recordset using the Open method of the recordset object with inline SQL. However I am trying to be consistent with my code by using the Command object to execute a Query. Here is the code:
'---------------------------------------------------------------------
'This code works OK, (lstPrices is a Listbox)
'---------------------------------------------------------------------
SQL = "SELECT PriceBreakstart, PriceBreakEnd, TradePrice, BookPrice "
SQL = SQL & "FROM Prices WHERE ProductID = " & ProductID
With rs
.ActiveConnection = CurrentProject.Connection
.CursorLocation = adUseClient
.LockType = adLockReadOnly
.Open SQL
End With
Set lstPrices.Recordset = rs
'--------------------------------------------------------------------
' but the following code doesn't. The Query qryGetPrices works OK and it
'produces a recordset with data in it. However when I try to assign
'the recordset rs to the Listbox lstPrices it produces the error:
'Runtime Error 7965:
'The object you entered is not a vaild recordset property
'
'--------------------------------------------------------------------
With cmd
.ActiveConnection = CurrentProject.Connection
.CommandText = "[qryGetPrices]"
.CommandType = adCmdTable
.Parameters("[Enter Product ID]") = ProductID
End With
Set rs = cmd.Execute
Set lstPrices.Recordset = rs 'Error occurs on this line
I cannot see the problem because in both cases I appear to have a valid recordset. Any ideas please, thanks
I have a problem assigning a recordset to a listbox when I create it using the Command object. It works OK when I create the recordset using the Open method of the recordset object with inline SQL. However I am trying to be consistent with my code by using the Command object to execute a Query. Here is the code:
'---------------------------------------------------------------------
'This code works OK, (lstPrices is a Listbox)
'---------------------------------------------------------------------
SQL = "SELECT PriceBreakstart, PriceBreakEnd, TradePrice, BookPrice "
SQL = SQL & "FROM Prices WHERE ProductID = " & ProductID
With rs
.ActiveConnection = CurrentProject.Connection
.CursorLocation = adUseClient
.LockType = adLockReadOnly
.Open SQL
End With
Set lstPrices.Recordset = rs
'--------------------------------------------------------------------
' but the following code doesn't. The Query qryGetPrices works OK and it
'produces a recordset with data in it. However when I try to assign
'the recordset rs to the Listbox lstPrices it produces the error:
'Runtime Error 7965:
'The object you entered is not a vaild recordset property
'
'--------------------------------------------------------------------
With cmd
.ActiveConnection = CurrentProject.Connection
.CommandText = "[qryGetPrices]"
.CommandType = adCmdTable
.Parameters("[Enter Product ID]") = ProductID
End With
Set rs = cmd.Execute
Set lstPrices.Recordset = rs 'Error occurs on this line
I cannot see the problem because in both cases I appear to have a valid recordset. Any ideas please, thanks