I have a parameter query asking the user to enter an Invoice Number. My parameter query is as follow:
Field: InvoiceNum
Table: Invoices
Criteria: In (select top 1 [InvoiceNum] from Invoices where [AccountNum]=[Customers].[AccountNum] and [InvoiceNum]<[Enter Invoice Number] order by [InvoiceNum] DESC)
Field: AccountNum
Table: Invoices
Field: Payment
Table: Invoices
When a user enters an Invoice Number, the result will give the lastest invoice that has an Invoice Number less than the Invoice Number the user entered for each Account Number as well as the Payment the customer paid for each of those invoice.
This works great except when the user happens to enter the smallest Invoice Number. Meaning there is no other Invoice Number smaller than the Invoice Number the user entered. The query will give no result.
That is not what I want. I want the query to return the result as stated above if there are invoices with Invoice Number less than what the user entered, else if there is no other Invoice Number smaller than the one entered by the user then return only the Invoice Number, Account Number, and Payment of that particular Invoice Number entered by the user.
Any help on this is greatly appreciated. Thank you.
Field: InvoiceNum
Table: Invoices
Criteria: In (select top 1 [InvoiceNum] from Invoices where [AccountNum]=[Customers].[AccountNum] and [InvoiceNum]<[Enter Invoice Number] order by [InvoiceNum] DESC)
Field: AccountNum
Table: Invoices
Field: Payment
Table: Invoices
When a user enters an Invoice Number, the result will give the lastest invoice that has an Invoice Number less than the Invoice Number the user entered for each Account Number as well as the Payment the customer paid for each of those invoice.
This works great except when the user happens to enter the smallest Invoice Number. Meaning there is no other Invoice Number smaller than the Invoice Number the user entered. The query will give no result.
That is not what I want. I want the query to return the result as stated above if there are invoices with Invoice Number less than what the user entered, else if there is no other Invoice Number smaller than the one entered by the user then return only the Invoice Number, Account Number, and Payment of that particular Invoice Number entered by the user.
Any help on this is greatly appreciated. Thank you.