Link to home
Start Free TrialLog in
Avatar of MikeDTE
MikeDTEFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Setting a Form's Recordset Order

I have a recordset of payments made for attending an Event.  Typically these are a deposit, a staged payment and a final payment.  The payments are displayed in a form and there are Next and Previous buttons to scroll through the payments in date of payment order.

The form fJDWEventPay is called from the form fJDWBookings with the following code snippet.

In Form_Load of fJDWEventPay I set on a filter with the passed argument - as follows:

'set filter
 Me.Filter = "jdwp_BookingRef = " & Me.OpenArgs
 Me.FilterOn = True

and I set the order - as follows:

'set order
Me.OrderBy = "jdwp_Date"
Me.OrderByOn = True

... but the first payment record to display is not always the first record by date - it's the second or third (appears to be entirely random).

I have tried setting the order and then the filter but it makes no difference

Any ideas anybody?
Dim lngNoBookings as Long
Dim stDocName As String

lngNoBookings = DCount("*", "tJDWBookings", "jdwb_Event=" & lngEventID & " And jdwb_BookingID=" & lngBookingID & " and jdwb_Status=" & Chr(34) & strStatus & Chr(34))
      
    If lngNoBookings > 0 Then
                
        stDocName = "fJDWEventPay"
        
        DoCmd.OpenForm stDocName, , , , , acDialog, lngBookingID  ' pass Open Args
     
    Else

        MsGBox "No Bookings ... " 'etc

    End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What's the Recordsource of the Form? Is it based on a Query, a Table, or a SELECT statement (or something else)?

Is the jdwp_Date field an actual Date datatype?

By "entirely random", do you mean that the order changes (i.e. Record #1 is in slot #1, but if you reopen the form Record #1 is now in the Slot #3, eg), or that it's always the same, but not in the right order?
Avatar of MikeDTE

ASKER

The recordsource is a table with a filter.  The jdwp_Date is a date field.

The Me.OrderBy = "cdate(jdwp_Date)" resolves the problem.  I have legacy data and some of the Date fields in the tables are defined differently from others.  jdwp_Date was one of them.

Thanks for the posts - now sorted
Avatar of MikeDTE

ASKER

Excellent advice - as usual