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
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
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.
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.
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.
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.
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
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.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
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.
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
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.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
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.