I have a form which executes a function on startup to see if a user exists. My probelm is that I can't return the result from the function back to the calling sub! I can output the result from the function, but it doesn't transfer this value back for evaluation! Please help, i'm sure it's something simple?
Private Sub Form_Timer()
Dim var_GetUserName
var_GetUserName = Environ("UserName")
Dim var_SQL 'SQL statement to be run
Dim var_SQL_Result 'SQL Result
var_SQL = "SELECT UserID AS rst_Result FROM tbl_Users WHERE UserID = """ & var_GetUserName & """ "
var_SQL_Result = RunSQLStatementInVBA(var_SQL)
Me.TimerInterval = 0
End Sub
Public Function RunSQLStatementInVBA(var_SQL)
Dim rst As DAO.Recordset
Dim var_SQLResult
Set rst = CurrentDb.OpenRecordset(var_SQL)
var_SQLResult = rst!rst_Result
rst.Close
Set rst = Nothing
End Function
Private Sub Form_Timer()
Dim var_GetUserName
var_GetUserName = Environ("UserName")
Dim var_SQL 'SQL statement to be run
Dim var_SQL_Result 'SQL Result
var_SQL = "SELECT UserID AS rst_Result FROM tbl_Users WHERE UserID = """ & var_GetUserName & """ "
var_SQL_Result = RunSQLStatementInVBA(var_SQL)
Me.TimerInterval = 0
End Sub
Public Function RunSQLStatementInVBA(var_SQL)
Dim rst As DAO.Recordset
Dim var_SQLResult
Set rst = CurrentDb.OpenRecordset(var_SQL)
var_SQLResult = rst!rst_Result
rst.Close
Set rst = Nothing
End Function