View Full Version : Question ListBox Question


Steve090874
08-05-2008, 04:49 PM
Hello,
This is my first time on this forum and new to Access so please be nice ha ha.

Just a quick question.
I have a date field on a form called "Wednesday" and also a Listbox called "List4" which contains dates gathered from a query
Is is possible to make an if statement to see if the Date in "Wednesday" is already in "List4"?
I have tried but i have had no success:

WayneRyan
08-05-2008, 06:36 PM
Steve,

You have to loop through the ListBox:


Private Function blnCheckList() As Boolean
Dim i As Integer
blnCheckList = False
For i = 0 TO Me.List4.ListIndex - 1
If Me.List4.ItemData(i) = Me.YourDateField Then
blnCheckList = True
Exit Function
End If
Next i

End Function


Wayne

Steve090874
08-05-2008, 06:43 PM
Steve,

You have to loop through the ListBox:


Private Function blnCheckList() As Boolean
Dim i As Integer
blnCheckList = False
For i = 0 TO Me.List4.ListIndex - 1
If Me.List4.ItemData(i) = Me.YourDateField Then
blnCheckList = True
Exit Function
End If
Next i

End Function


Wayne
Wayne,

Thanks for your help but i have two questions:

1/ If i wanted to add an If statement that would place a "Y" in a box called "txt01" if a date was found where in your code would i place it?

2/ Where would i place this code ie on a command button?

neileg
08-06-2008, 02:46 AM
You don't have to loop through the list box, you could do a DCount() based on the query that feeds the listbox.

Steve090874
08-06-2008, 07:01 AM
Hi,
As stated previously i am new to Access and this Forum could you please offer a little more information

WayneRyan
08-06-2008, 08:36 AM
Steve,

You'd post it right after the line:

blnCheckList = True

btw,
Neil is right if you have a query that feeds your listbox, you could use the
DCount function to make the check.

Either way, we'd need more info to assist further.

Maybe a small sample DB.

hth,
Wayne

Steve090874
08-06-2008, 09:31 AM
Hi,
Sorry i should of supplied more info. My problem is that i have a form which is used to book dates against a employee. I have a SubForm placed on the form that shows all dates currently booked against that employee, which automatically populates when the EmployeeID is entered into the Form.
I am trying to find a way to stop the same date being booked against the same employee.
The Employee info is stored on one table and the dates are stored on another using the EmployeeID as the join for both.
I know my original question was in regard to ListBoxes but i think a Subform might be easier, i have attached a sample of the Database