Requering listbox records based on another listbox (1 Viewer)

TimTDP

Registered User.
Local time
Today, 22:09
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
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:09
Joined
Oct 29, 2018
Messages
21,687
Maybe try assigning the first row value to the listbox instead.
 

LarryE

Active member
Local time
Today, 12:09
Joined
Aug 18, 2021
Messages
649
Try replacing the Like with =
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:09
Joined
Feb 19, 2002
Messages
43,961
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:

June7

AWF VIP
Local time
Today, 11:09
Joined
Mar 9, 2014
Messages
5,525
If there is time component, use DateValue(fieldname) to extract date part.
 

cheekybuddha

AWF VIP
Local time
Today, 20:09
Joined
Jul 21, 2014
Messages
2,400
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];
 

TimTDP

Registered User.
Local time
Today, 22:09
Joined
Oct 24, 2008
Messages
213
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

  • Select ListBox Record Using VBA.zip
    134.5 KB · Views: 5

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:09
Joined
May 7, 2009
Messages
19,278
here check the change in code of the button.
 

Attachments

  • Select ListBox Record Using VBA.zip
    130.2 KB · Views: 3

cheekybuddha

AWF VIP
Local time
Today, 20:09
Joined
Jul 21, 2014
Messages
2,400
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

Top Bottom