Topic: Runtime 13 Type Mismatch error - cancel All
(2 messages, Page 1 of 1)
We use VBA in MS Access and would like to cancel all orders for a single contact Based on the Orders' state. After it meets the criteria within the If statement, we used a DAO.recordset to retrieve the OderID, from our local table, which the table was filled with the orders data previously including their OrderID.
Problem is; the OrdersApi.CancelOrder fails with Runtime 13 Type Mismatch error. Our parameters have the correct data type for the criteria required. They are; Long for the OrderID and 0 (as "Manual") for the type, we left the "Location" blank since it's optional.
'Created MSansa 2020-1214
On Error GoTo Err_CancelWorkingOrders
Dim i As Integer
Dim Order As GF_Api_COM.Order
Dim cd As DAO.Database, rsc As Recordset
Dim cSQL As String
'refresh the list of active orders
If (api Is Nothing) Then Set api = Glob.c
If (apiOrders Is Nothing) Then Set apiOrders = api.orders
'Stop 'Stops when "Suspend Trading" is checked on the Login window.
If Not apiOrders Is Nothing Then
For i = 0 To apiOrders.Get().Count - 1
Set Order = apiOrders.Get().GetAt(i)
If Order.Contract = aryCommodities(lPointer).Base_Contract Then
If Order.CurrentState = OrderState_Working _
Or Order.CurrentState = OrderState_Sent _
Or Order.CurrentState = OrderState_Held Then
'the Old API command that cancels an order,search for ActiveOrder
' Glob.c.CancelOrder Order
' or Glob.c.CancelOrder ActiveOrder
'Cancel all orders for the same Contract
cSQL = "Select clng([Order]) From tblActiveOrders_temp " _
& "Where Symbol='" & aryCommodities(lPointer).Base_Contract & "';"
Set cd = CurrentDb: Set rsc = cd.OpenRecordset(cSQL)
If rsc.EOF Then Exit Function
Do Until rsc.EOF
apiOrders.CancelOrder rsc(0), SubmissionType_Manual
End If 'Order state
End If 'Order contracts
End If 'Order Api'
On Error Resume Next
Set rsc = Nothing: Set cd = Nothing
Set Order = Nothing: Set apiOrders = Nothing
gParms = CStr(lPointer)
Call LogError(Err.Number, Err.Description, "NESClass", "CancelALLWorkingOrders()", gParms)
Joined: Aug 24, 2017
Probably you are getting a Type Mismatch error because you are passing a long instead of OrderID.