Results 1 to 5 of 5
  1. #1
    shaunacol is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    55

    Set a value of a combo box to be results of a query

    I have a table called tbl_Session which, when user logs on, records their Staffname, Stafflocation and current date time, it is not related to any other table. I then have a form called Frm_Order based on tbl_Order where the user can enter a new order. What would be extremely useful is if I could grab the fields StaffName and StaffLocation from tbl_Session and insert automatically into tbl_Order StaffName and StaffLocation for that particular order. I have tried setting the default value to a query based on tbl_Session where LogOffDate is empty (i.e current session). I have also tried writing some VBA for a Dlookup but I cant get the syntax right. Can anyone help please?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    When user clicks the CREATE NEW button,
    open the form,
    then set each field from the user info on the other form. This would happen on the FORM_LOAD event.
    txtUser = forms!frmUser!txtStaffName
    txtSession = forms!frmUser!ID

  3. #3
    shaunacol is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    55
    I'm sorry I think I may be confused. My user logon form will no longer be open as once they have logged on it automatically closes so I cant set my fields in the order form to be the same as my logon form fields (or maybe im misinterpreting?). I have to somehow get the data from tbl_session but since I need the current session then that's why I created a query that only has records where the LogOffDate is null (to capture current session). I hope that makes sense.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Options:

    1. save the info to global variables or TempVars

    2. pass values to the OrderForm from the logon form and set unbound textboxes - I do this with form OpenArgs argument of DoCmd.OpenForm method

    3. have a form that never closes (like a MainMenu) and pass values to that form so they remain available for reference anywhere at any time - this is what I do

    4. DLookup() - post your attempted code
    However, since this is a multi-user database, there could be multiple users logged on at the same time and therefore multiple records where LogOffDate Is Null - so I don't see this as a practical approach.

    My db logon procedure pulls username from network and searches for that in Users table. If not found, they are a new user and they will be presented with logon form so a new record can be created. They never see the logon form again. This does take it for granted they are valid user because they logged into the network.
    Last edited by June7; 07-08-2015 at 04:20 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    shaunacol is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    55
    Many thanks for your reply, that makes sense, ill try that now

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

Similar Threads

  1. Replies: 3
    Last Post: 10-22-2014, 09:44 AM
  2. Combo Box with Query Results Issue
    By dascoli in forum Access
    Replies: 9
    Last Post: 08-13-2014, 12:09 PM
  3. Replies: 4
    Last Post: 02-22-2012, 12:43 PM
  4. Replies: 4
    Last Post: 08-16-2011, 05:54 PM
  5. Replies: 1
    Last Post: 03-09-2011, 02:04 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