Results 1 to 8 of 8
  1. #1
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156

    List box Default

    I have a form with a list box. I would like the list box to load with the first name in the list and not blank as it is doing now. I am suing Access 2016.



    Thank-you

    Cheeco

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I don't blame you for suing Access 2016!

    Get the sort order right, and have a criteria of not null in the SQL row source of the listbox.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    That should eliminate the blank row in the listbox but does not actually select the item. Do you want the item selected as well?
    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.

  4. #4
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    Can I ask what is the point of a one item list box? Or am I missing something?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156
    Right now when the form loads the list box is blank. What I want to happen is when the form loads the first name in the combo box list to appear in the combo box.

  6. #6
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156
    The DB is a calendar to keep track of time off. When the form load the Combo box is blank. If the combo box is blank and the user clicks on the button to go to the next month then a error pops up. "Run-Tie error 94, Invalid use of Null" Now this error pops up when trying to go Previous and next month and Previous and next year. But if the user clicks the combo box and chooses an employee then the error does not pop up and every thing works fine. I have pasted a copy of the code for the

    Code:
    Private Sub MonthNextBut_Click()   
       If Me.CalMonth < 12 Then
          Me!CalMonth = Me!CalMonth.Column(0) + 1
       Else
          Me!CalMonth = 1
          Me!CalYear = Me!CalYear + 1
       End If
       
       Call Cal([CalMonth], [CalYear], Me.cboUser)
       If IsNull(Me.cboUser) = False Then Call SetCalendar
    Me.[qryTableInput subform].Requery
    End Sub
    The line in Bold is the line that is highlighted in yellow when the error pops up. Like I said if the user chooses and employee first no error.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    You are referencing listbox and combobox in your narratives. Exactly what type of control are you working with?

    Review https://www.fmsinc.com/MicrosoftAcce...ect-first.html

    Or don't run the code if no value in combobox.

    If IsNull(Me.cboUser) Then
    MsgBox "Select user"
    Else
    ...
    End If
    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.

  8. #8
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    I think OP is calling the combo list a list box. If so, Cheeco, you are confusing us.
    What's also missing is the code that you named Cal. That procedure probably doesn't like the fact that sometimes, the combo contains no value.
    You have 2 issues here.
    - You are trying to do stuff with a combo value but there isn't one (the cause for the error).
    - You want to automatically assign the first list value to it, likely as the means for eliminating the error.

    Forget the second, fix the first. June7 has given you the answer - check if the combo is null (you might also want to check if it contains an empty string or simple space but let's keep it simple for now). Or you have to modify the Cal procedure to accept no value when the combo is null. Try

    Code:
    Private Sub MonthNextBut_Click()   
       If Me.CalMonth < 12 Then
          Me.CalMonth = Me.CalMonth.Column(0) + 1
       Else
          Me.CalMonth = 1
          Me.CalYear = Me.CalYear + 1
       End If
       
      If Not IsNull(Me.cboUser) Then
       Cal [CalMonth], [CalYear], Me.cboUser
      Else
       SetCalendar
      End If
    
    Me.[qryTableInput subform].Requery '< this works??
    
    End Sub
    You should only use the bang ! operator when required. Your way causes the form control reference to not be evaluated at compile time, which can result in errors during code execution if the reference is invalid. Also, I removed the Call statement. Not wrong to use it, I guess, but it's not required if the procedure being called is not a function that returns a value. It seems yours does not. Put it back the way you had it if it doesn't work or you don't like it.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 8
    Last Post: 12-13-2017, 10:38 AM
  2. Replies: 1
    Last Post: 03-19-2016, 03:56 AM
  3. Replies: 8
    Last Post: 05-25-2013, 05:24 PM
  4. Replies: 3
    Last Post: 05-13-2011, 08:48 AM
  5. Replies: 13
    Last Post: 02-08-2011, 11:53 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