Results 1 to 9 of 9
  1. #1
    jeffyyy is offline Novice
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Posts
    7

    Show data from query in a text box

    OK, I have a form based on the table [Residents]. I also have a table that is called [Units]. They are related by the field Res_Id. In the units table, I have all of the residents current and previous unit and am using the query to select only the "active" unit (as defined by a yes/no checkbox). So the query works. Now, on the form I need it to grab the room number of the current resident selected on the form from the query and display it in a textbox.

    Hopefully I explained all the enough. Thanks for the help!

  2. #2
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    From your description it sounds like you could set the Text Box's Control Source to use the Room number from the query.

  3. #3
    jeffyyy is offline Novice
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Posts
    7
    I tried that, but I get the #Name error. I would assume that is because the form is based on the table residents and not the query I am getting the room number from.

  4. #4
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    You could create a query which uses the residents table and the other query and set it as the data source for the form.

    If the current query references the residents table you could edit it to include the rest of the the fields from residents and then use that query as the form's record source.

    Another way would be to use the DLookup function. The best method really depends on how the DB is structured.

  5. #5
    jeffyyy is offline Novice
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Posts
    7
    How would I go about using the Dlookup function? I tried creating a query to include all that information and changed the form to be based off of the query, and it caused all sorts of problems with a couple of my dropdowns.

    Thanks for the help!

  6. #6
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    In the Control Source of the field type in something like:

    Code:
    =DLookup("RoomNumber", "qryName", "ResID=" & [ResID])
    In this sample:
    - "RoomNumber" refers to a field in the query which contains the Room Number you want.
    - "qryName" refers to the name of the query where the Room Number is found.
    - It assumes ResID is a number.

    If RedID is a string use this format to wrap the data in quotes:
    Code:
    =DLookup("RoomNumber", "qryName", "ResID=" & Chr(34) & [ResID] & Chr(34))

  7. #7
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    Personally, I would use the query for the form and try to figure out the problems with the combo boxes because DLookup can cause a bit of lag if you have a lot of records.

  8. #8
    jeffyyy is offline Novice
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Posts
    7
    I just implemented the DLookup, and it is a little laggy, but nothing too bad. I do not expect a lot of records in that table, as we do not move residents (or get new residents) very frequently, so a little lag on that form is not a huge deal.

    THANKS for your help!

  9. #9
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    My pleasure. Have a good weekend.

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

Similar Threads

  1. Replies: 0
    Last Post: 10-06-2010, 11:56 AM
  2. Open a text file to show results...
    By kkrishna in forum Programming
    Replies: 3
    Last Post: 08-13-2010, 09:38 AM
  3. Replies: 0
    Last Post: 07-20-2010, 12:44 PM
  4. Replies: 1
    Last Post: 05-17-2010, 12:21 PM
  5. Text Box to show specific record
    By chu3w in forum Forms
    Replies: 1
    Last Post: 04-01-2010, 12:23 PM

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