Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    buckwheat is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    144

    List Box Focus


    Hi,

    Can anyone tell me if there is a way to customize a list box so the focus is on the "column header" when the form opens? My source for the list box is a query, and the source for the query is a "linked" table, so I'm not able to add a blank row directly into the table. When the form opens, all fields, need to be blank, but since the list box is always populated, the first patient's name is always selected; a cbo is not an option.

    Many thanks.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You might try leaving the RowSource for the ListBox blank and set it in the OnEnter or GotFocus event.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You could use a union query. This seems to give the results you want...

    You have to use SQL view to create a union query. Create the main query (you already have that). Then add the 2nd query. It has to have the same number of fields. Doesn't matter what the field names are . Here is an example of the query I used to test this:
    Code:
    SELECT [010_Clients].ClientID, [010_Clients].FirstName, [010_Clients].MiddleNmae, [010_Clients].LastName, [010_Clients].Available 
    FROM 010_Clients 
    
    UNION 
    
    SELECT "" as A, "" as B, "" as c, "" as d, "" as e FROM 010_Clients
    ORDER BY [010_Clients].LastName, [010_Clients].FirstName;


    Note: The ORDER BY clause is after the second query; the field names are taken from the first query.

  4. #4
    buckwheat is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    144
    Steve, not sure how a union query would put focus on the header of the list box. Can you explain a little more so I can understand better please?

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Can anyone tell me if there is a way to customize a list box so the focus is on the "column header" when the form opens?
    AFAIK, there is no way to select (set the focus to) the "column header"


    My source for the list box is a query, and the source for the query is a "linked" table, so I'm not able to add a blank row directly into the table.
    This is what the union query would do. The blank line (record) is not in the table, just in the list box as the first record.


    When the form opens, all fields, need to be blank,
    Then RuralGuy's suggestion would probably be best.



    If you put a space in a list of letters and sort ascending, the space will always be at the top. Using the union query for the list box record source, the blank line (record) will be at the top of the list box (selected).

  6. #6
    buckwheat is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    144
    Steve, I tried the Union query because I didn't know exactly what the code should be for Rural Guys solution . . . the Union query worked perfectly . . . never used a Union query before, pretty neat! The form now opens with focus on the first blank row in the list box. The next question I have and was probably answered regarding a cbo box scenario, but I'll ask anyway: the List box is on the main form, I have a subform with 4 cbo that I am using as a "data entry" form returning data to a main table for the patient name selected from the list box. I have a button with the code below that clears out the 4 cbo boxes for the next record. Is there a way that I can code to this button that also returns the List Box that is on the main form to the first blank row? I've tried to manipulate the code below without success.


    Private Sub cmdSaveEnc_Click()
    On Error GoTo Err_cmdSaveEnc_Click

    DoCmd.GoToRecord , , acNewRec

    Exit_cmdSaveEnc_Click:
    Exit Sub
    Err_cmdSaveEnc_Click:
    MsgBox Err.Description
    Resume Exit_cmdSaveEnc_Click

    End Sub

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Is the list box bound or unbound?
    Is the list box single select or multi-select?

  8. #8
    buckwheat is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    144
    single select, bound

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is the RowSource of the List box a query?

  10. #10
    buckwheat is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    144
    Yes, the source is a query.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    All you should have to do in the OnEnter Evernt is Me.ListBoxName.RowSource = "YourQueryName"

  12. #12
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Is there a way that I can code to this button that also returns the List Box that is on the main form to the first blank row?
    single select, bound
    Since the list box is bound, if you "clear" it (go to the blank first row), you will change the main form record.

    The list box would have to be unbound to be able to "reset" the list box to the blank first row.

  13. #13
    buckwheat is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    144
    thanks for your help

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is this thread now Solved? There is a tool under Thread Tools at the top of the thread to mark it so. What solution did you use?

  15. #15
    buckwheat is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    144
    based on Steve's comments, I wasn't sure how to proceed, so I think I will switch it back to a cbo and work from there. Thanks again.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. hide a list box on lost focus
    By markjkubicki in forum Programming
    Replies: 2
    Last Post: 08-18-2012, 10:32 AM
  2. Set Focus on Subform
    By GCS in forum Forms
    Replies: 1
    Last Post: 12-01-2011, 11:46 AM
  3. Focus on Key Control
    By windwardmi in forum Access
    Replies: 1
    Last Post: 09-07-2011, 04:57 PM
  4. Will not set focus
    By AKQTS in forum Programming
    Replies: 4
    Last Post: 05-04-2011, 06:38 AM
  5. Keeping focus
    By ronatnc in forum Forms
    Replies: 0
    Last Post: 12-16-2008, 12:32 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