How do I assign a function that returns a value to a variable?
So I have a class called Transactions and I put all my functions there. The problem is, when I try to call that specific function and assign it to a开发者_C百科 variable, there is a "ByRef Argument Type mismatch" error that keeps on bugging me. Help please :)
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
The way it is, only password is being declared as string, the other 2 are object.
So change the code to this and the error will go away:
Dim name As String, username As String, password As String
精彩评论