ASC and DESC sortinging of multiple controls

J

Jane

Hello everyone

I wonder if you could help me with this problem.

I found some code on Google and I can not get it to work

I have a continuous form that includes the controls called
StudentFirstName and StudentSurname
linked to table field names called the same

I would like to sort the form by the 1st and 2nd name and then if clicked
again reverse the sorting.

This is the code I have that is not working and I hope you will be able to
spot were I am going wrong.

Private Sub SortStudentsButton_Click()
If IsNull(Me.OrderBy) Or Me.OrderBy = "[StudentFirstName],[StudentSurname]
DESC" Then
Me.OrderBy = "[StudentFirstName],[StudentSurname]"
Else
Me.OrderBy = "[StudentFirstName],[StudentSurname]" & " DESC"
End If
Me.OrderByOn = True
End Sub


Thank you

Jane Hollin
 
D

Douglas J. Steele

What does "not working" mean in this context? Do you get an error message?
If so, what is it? If you don't get an error message, what does happen, and
what do what to have happen instead?

One thing that pops out at me is that you probably want

Me.OrderBy = "[StudentFirstName] DESC,[StudentSurname] DESC"

instead of

Me.OrderBy = "[StudentFirstName],[StudentSurname]" & " DESC"
 
J

Jane

Thank you for answering Mr Streel

The problem is that it will sort on the 1st click but will not revers the
sort on the 2nd click

Thank you



Douglas J. Steele said:
What does "not working" mean in this context? Do you get an error message?
If so, what is it? If you don't get an error message, what does happen, and
what do what to have happen instead?

One thing that pops out at me is that you probably want

Me.OrderBy = "[StudentFirstName] DESC,[StudentSurname] DESC"

instead of

Me.OrderBy = "[StudentFirstName],[StudentSurname]" & " DESC"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Jane said:
Hello everyone

I wonder if you could help me with this problem.

I found some code on Google and I can not get it to work

I have a continuous form that includes the controls called
StudentFirstName and StudentSurname
linked to table field names called the same

I would like to sort the form by the 1st and 2nd name and then if clicked
again reverse the sorting.

This is the code I have that is not working and I hope you will be able to
spot were I am going wrong.

Private Sub SortStudentsButton_Click()
If IsNull(Me.OrderBy) Or Me.OrderBy = "[StudentFirstName],[StudentSurname]
DESC" Then
Me.OrderBy = "[StudentFirstName],[StudentSurname]"
Else
Me.OrderBy = "[StudentFirstName],[StudentSurname]" & " DESC"
End If
Me.OrderByOn = True
End Sub


Thank you

Jane Hollin
 
J

Jane

Hello again Mr Steel,

Thank you I have managed to get it working.

Jane Hollin


Douglas J. Steele said:
What does "not working" mean in this context? Do you get an error message?
If so, what is it? If you don't get an error message, what does happen, and
what do what to have happen instead?

One thing that pops out at me is that you probably want

Me.OrderBy = "[StudentFirstName] DESC,[StudentSurname] DESC"

instead of

Me.OrderBy = "[StudentFirstName],[StudentSurname]" & " DESC"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Jane said:
Hello everyone

I wonder if you could help me with this problem.

I found some code on Google and I can not get it to work

I have a continuous form that includes the controls called
StudentFirstName and StudentSurname
linked to table field names called the same

I would like to sort the form by the 1st and 2nd name and then if clicked
again reverse the sorting.

This is the code I have that is not working and I hope you will be able to
spot were I am going wrong.

Private Sub SortStudentsButton_Click()
If IsNull(Me.OrderBy) Or Me.OrderBy = "[StudentFirstName],[StudentSurname]
DESC" Then
Me.OrderBy = "[StudentFirstName],[StudentSurname]"
Else
Me.OrderBy = "[StudentFirstName],[StudentSurname]" & " DESC"
End If
Me.OrderByOn = True
End Sub


Thank you

Jane Hollin
 
K

kc-mass

What was the solution?

Jane said:
Hello again Mr Steel,

Thank you I have managed to get it working.

Jane Hollin


Douglas J. Steele said:
What does "not working" mean in this context? Do you get an error
message?
If so, what is it? If you don't get an error message, what does happen,
and
what do what to have happen instead?

One thing that pops out at me is that you probably want

Me.OrderBy = "[StudentFirstName] DESC,[StudentSurname] DESC"

instead of

Me.OrderBy = "[StudentFirstName],[StudentSurname]" & " DESC"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Jane said:
Hello everyone

I wonder if you could help me with this problem.

I found some code on Google and I can not get it to work

I have a continuous form that includes the controls called
StudentFirstName and StudentSurname
linked to table field names called the same

I would like to sort the form by the 1st and 2nd name and then if
clicked
again reverse the sorting.

This is the code I have that is not working and I hope you will be able
to
spot were I am going wrong.

Private Sub SortStudentsButton_Click()
If IsNull(Me.OrderBy) Or Me.OrderBy =
"[StudentFirstName],[StudentSurname]
DESC" Then
Me.OrderBy = "[StudentFirstName],[StudentSurname]"
Else
Me.OrderBy = "[StudentFirstName],[StudentSurname]" & " DESC"
End If
Me.OrderByOn = True
End Sub


Thank you

Jane Hollin
 
J

Jane

Hi

This seems to work fine

If Me.OrderBy = "[StudentFirstName],[StudentSurname]" Then
Me.OrderBy = "[StudentFirstName] DESC , [StudentSurname] DESC"
Me.OrderByOn = True
Else
Me.OrderBy = "[StudentFirstName] , [StudentSurname]"
Me.OrderByOn = True
End If

I moved the Me.OrderByOn = True to both sections and it seems to improve
it, I don't know why though.
And I followed Mr Steele's advice regarding adding DESC to each items on the
second line

Jane Hollin




kc-mass said:
What was the solution?

Jane said:
Hello again Mr Steel,

Thank you I have managed to get it working.

Jane Hollin


Douglas J. Steele said:
What does "not working" mean in this context? Do you get an error
message?
If so, what is it? If you don't get an error message, what does happen,
and
what do what to have happen instead?

One thing that pops out at me is that you probably want

Me.OrderBy = "[StudentFirstName] DESC,[StudentSurname] DESC"

instead of

Me.OrderBy = "[StudentFirstName],[StudentSurname]" & " DESC"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Hello everyone

I wonder if you could help me with this problem.

I found some code on Google and I can not get it to work

I have a continuous form that includes the controls called
StudentFirstName and StudentSurname
linked to table field names called the same

I would like to sort the form by the 1st and 2nd name and then if
clicked
again reverse the sorting.

This is the code I have that is not working and I hope you will be able
to
spot were I am going wrong.

Private Sub SortStudentsButton_Click()
If IsNull(Me.OrderBy) Or Me.OrderBy =
"[StudentFirstName],[StudentSurname]
DESC" Then
Me.OrderBy = "[StudentFirstName],[StudentSurname]"
Else
Me.OrderBy = "[StudentFirstName],[StudentSurname]" & " DESC"
End If
Me.OrderByOn = True
End Sub


Thank you

Jane Hollin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top