Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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
like image 895
Ali Avatar asked Feb 23 '26 10:02

Ali


1 Answers

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
like image 74
ariel Avatar answered Feb 26 '26 01:02

ariel