2016-08-25 42 views
0

你好我嘗試編寫返回對象的功能,但它給了我一個參數不可選的錯誤,這是我的代碼如何接受參數的Visual Basic函數返回一個對象6

Public Function searchVehicle(c As String, v As Variant) As Collection 
    Dim qur As String 
    qur = "select * from [vehicle] where (" & c & " like '%" & v & "%')" 
    Set mobjRst = conn.execQuery(qur) 
    Dim tmpV As Vehicle 
    Dim res As Collection 
    With mobjRst 
    Do Until .EOF 
    Set tmpV = New Vehicle 
    Call tmpV.popVehicle(!ID, !make, !model, !purchaseyear, !totalmilage, !milageafterservice, !servicemilage, !description) 
    res.Add (tmpV) 
    .MoveNext 
    Loop 
    End With 
searchVehicle = res 
End Function 
+1

錯誤出現在哪一行? –

+0

不會向我們顯示導致錯誤的代碼行,它最有可能是您的Vehicle類的popVehicle方法 - 但是直到您告訴我們它在哪條線上......這是一個猜測 – dbmitch

+0

您如何調用該函數? – Smith

回答

1

你的問題主要表現在以下調用函數 -

searchVehicle = res 

您已指定searchVehicle具有組合集合的字符串(c)和變體(v)。這將作爲錯誤你有沒有設定值C或V之後,再打電話給你的函數 -

searchVehicle = (c, v) collection 

給我們你怎麼稱呼這等你的按鈕單擊事件,返回什麼一些更多的信息.​​..

相關問題