Hi,
I am trying to assign a variable at run time to a record in table named users.
username1 = CurrentDb.Execute("Select UserName from users where UserID = " & Me.user1.Value)
but it is giving an error.
Hi,
I am trying to assign a variable at run time to a record in table named users.
username1 = CurrentDb.Execute("Select UserName from users where UserID = " & Me.user1.Value)
but it is giving an error.
And the error is?
Use DlookUp().
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
Your code (assuming it works) is not assigning a variable to a record - its selecting a field in a record and assigning it to a variable
Here is the error:
compiler error:
Expected Function or variable
Your error is because Currentdb.Execute cannot be used with a select query.Code:username1 = CurrentDb.Execute("Select UserName from users where UserID = " & Me.user1.Value)
We need more context to provide meaningful suggestions.
What and where is username1?
Where does this code reside? Behind a form containing the control user1?
Without context, we have to guess and that leads to confusing replies based on different guesses.