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

        MsGBox "No Bookings ... " 'etc

    End If

Open in new window

Who is Participating?
mbizupConnect With a Mentor Commented:

It may depend on where jdwp_date is coming from (query or directly from a date field in a table).

See if this makes any difference:

Me.OrderBy = "cdate(jdwp_Date)"
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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?
MikeDTEAuthor Commented:
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
MikeDTEAuthor Commented:
Excellent advice - as usual
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.