如何分配一个向变量返回值的函数?

时间:2011-04-26 01:11:05

标签: vb.net ms-access-2007

所以我有一个名为Transactions的类,我将所有功能放在那里。问题是,当我尝试调用该特定函数并将其分配给变量时,会出现“ByRef Argument Type mismatch”错误,该错误一直困扰着我。请帮助:)

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 个答案:

答案 0 :(得分:1)

原样,只有密码被声明为字符串,另外2个是对象。

因此,请将代码更改为此,错误将消失:

Dim name As String, username As String, password As String