2011-04-26 119 views
3

所以我有一个叫Transactions的类,我把所有的功能放在那里。问题是,当我尝试调用该特定函数并将其分配给一个变量时,会出现一个“ByRef参数类型不匹配”错误,这个错误会一直困扰着我。请帮助:)如何分配一个返回值给变量的函数?

Public Function GetUserID(name As String) As Integer 
    Dim gotID As Integer 
    Dim rec As Recordset 
    Call connectDB 
    sSQL = "select ID from User where Name ='" & name & "'" 
    Set rec = CurrentDb.OpenRecordset(sSQL) 
    gotID = rec(0) 
    GetUserID = gotID 
End Function 

Private Sub btnAcctAdd_Click() 
    Dim tr As Transactions 
    Set tr = New Transactions 

    Dim ID as Integer 
    Dim name, username, password As String 

    name = cmbName.Value 
    'MsgBox name 
    ID = tr.GetUserID(name) 
    'MsgBox ID 
End Sub 

回答

1

它的方式是,只有密码声明为字符串,其他2个是对象。

因此,代码更改为这一点,错误将消失:

Dim name As String, username As String, password As String 
+0

它的工作!谢谢! :D – Ali 2011-04-26 01:28:11

+2

实际上,原始代码中的另外两个变量是Variant,而不是Object。 – RolandTumble 2011-04-26 18:12:00

相关问题