Results 1 to 5 of 5
  1. #1
    rwahdan1978 is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Jun 2024
    Posts
    57

    Assign variable to a record in table

    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.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    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

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,930
    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

  4. #4
    rwahdan1978 is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Jun 2024
    Posts
    57
    Here is the error:

    compiler error:
    Expected Function or variable

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    Code:
    username1 = CurrentDb.Execute("Select UserName from users where UserID = " & Me.user1.Value)
    
    Your error is because Currentdb.Execute cannot be used with a select query.

    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.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 17
    Last Post: 03-20-2023, 04:13 PM
  2. Can't assign listview to variable?
    By mrfrisky330 in forum Access
    Replies: 2
    Last Post: 12-04-2017, 10:56 AM
  3. Assign variable
    By beaurou in forum Modules
    Replies: 4
    Last Post: 11-21-2014, 12:01 PM
  4. Assign value to variable on other form
    By tylerg11 in forum Access
    Replies: 3
    Last Post: 08-20-2013, 07:48 AM
  5. Assign and call variable from table
    By smikkelsen in forum Access
    Replies: 7
    Last Post: 04-01-2010, 09:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums