Requering listbox records based on another listbox (1 Viewer)

TimTDP

Registered User.
Local time
Today, 16:36
Joined
Oct 24, 2008
Messages
213
I have 2 list box's on a form

lstPaymentDate = SELECT DISTINCT PaymentDate FROM tblPayment ORDER BY PaymentDate DESC;
lstSelectEmployee = SELECT tblPayment.EmployeeWageId FROM tblPayment WHERE (((PaymentDate) Like [Forms]![frmPrintPayment]![lstPaymentDate]));

Code:
Private Sub lstPaymentDate_AfterUpdate()
Me.lstSelectEmployee.Requery
end sub

This works perfectly

I have now added a command button

Code:
Private Sub cmdOneClickAll_Click()
Me.lstPaymentDate.Selected(0) = True
Me.lstSelectEmployee.Requery
end sub

When I click on the button, the 1st record in lstPaymentDate is selected, but no records appear in lstSelectEmployee (There are records!!!)

How do I get the records to display in lstSelectEmployee ?

Thanks in advance
 
Maybe try assigning the first row value to the listbox instead.
 
Try replacing the Like with =
 
Like is never used with numbers or dates. AND it is only used with partial strings AND wildcards. If you have trouble with = when working with dates, the most likely problem is that the date has a time component and so you have to use a range and do >= and <= or get rid of the time part since it is not relevant in this situation. Date is sufficient. That means you also need to understand the difference between Date() and Now(). Date() returns the current date ONLY. Now() returns the current date + the current time.
 
Last edited:
If there is time component, use DateValue(fieldname) to extract date part.
 
I also asked in the other thread on UA:

Please clarify whether lstPaymentDate is a single-select or multi-select listbox.

If its Multi Select property is set to anything other than "None" then the Rowsource will not work as you intend:
Code:
lstSelectEmployee = SELECT tblPayment.EmployeeWageId FROM tblPayment WHERE PaymentDate = [Forms]![frmPrintPayment]![lstPaymentDate];
 
Thanks for the help so far. But I simply cannot get it to work!
I have attached the database.

On the form that opens is a button. If the button is pressed, the second record in lstPaymentDate should be selected and lstSelectEmployee requeried.

Thanks in advance
 

Attachments

1-line code change required:

Change to:
Code:
Private Sub cmdOneClickAll_Click()
Me.lstPaymentDate = Me.lstPaymentDate.ItemData(0)
Me.lstSelectEmployee.Requery
end sub
 

Users who are viewing this thread

Back
Top Bottom