Sorting Buttons on Form

C

Coleman

I have a two column form that I wish to allow the user to sort by a File's
Index number or by a File's Name. I have assigned a button to each column
and the following code to enable an ascending order on click:

Button #1 looks like this:
__________________________________________________
Private Sub Sort_By_File_Index_Click()
On Error GoTo Err_Sort_By_File_Index_Click

strFileIndex#.SetFocus
DoCmd.RunCommand acCmdSortAscending

Exit_Sort_By_File_Index_Click:
Exit Sub

Err_Sort_By_File_Index_Click:
MsgBox Err.Description
Resume Exit_Sort_By_File_Index_Click

End Sub
_________________________________________________

and Button #2 looks similarly like this:
_________________________________________________
Private Sub Sort_By_File_Name_Click()
On Error GoTo Err_Sort_By_File_Name_Click

strFileName.SetFocus
DoCmd.RunCommand acCmdSortAscending

Exit_Sort_By_File_Name_Click:
Exit Sub

Err_Sort_By_File_Name_Click:
MsgBox Err.Description
Resume Exit_Sort_By_File_Name_Click

End Sub
_______________________________________________

My problem is when I click on Button #1, I get "Complie Error: Invalid
Qualifier", yet Button #2 works fine....and YES, the control name
"strFileIndex#" is correct.

Any ideas???????

Thanks,
Coleman
 
A

Allen Browne

If the field name includes characters other than A-Z, 1-9, or underscore,
you must enclose it in square brackets.

Try:
Me.[strFileIndex#].SetFocus

(The "Me." is optional, but helps identify what you are talking about.)
 
C

Coleman

Thanks for the feedback...Yes, I see what you are saying about the use of the
"#" sign...total overlook on my part, but I'm saved by the brackets.

Thanks again..
CH

fredg said:
I have a two column form that I wish to allow the user to sort by a File's
Index number or by a File's Name. I have assigned a button to each column
and the following code to enable an ascending order on click:

Button #1 looks like this:
__________________________________________________
Private Sub Sort_By_File_Index_Click()
On Error GoTo Err_Sort_By_File_Index_Click

strFileIndex#.SetFocus
DoCmd.RunCommand acCmdSortAscending

Exit_Sort_By_File_Index_Click:
Exit Sub

Err_Sort_By_File_Index_Click:
MsgBox Err.Description
Resume Exit_Sort_By_File_Index_Click

End Sub
_________________________________________________

and Button #2 looks similarly like this:
_________________________________________________
Private Sub Sort_By_File_Name_Click()
On Error GoTo Err_Sort_By_File_Name_Click

strFileName.SetFocus
DoCmd.RunCommand acCmdSortAscending

Exit_Sort_By_File_Name_Click:
Exit Sub

Err_Sort_By_File_Name_Click:
MsgBox Err.Description
Resume Exit_Sort_By_File_Name_Click

End Sub
_______________________________________________

My problem is when I click on Button #1, I get "Complie Error: Invalid
Qualifier", yet Button #2 works fine....and YES, the control name
"strFileIndex#" is correct.

Any ideas???????

Thanks,
Coleman

It's the use of the # symbol in the field name.
The # is a date delimiter symbol and your use of one here in the
control name is causing a compile error.

Either change the field name to something else, i.e. strFileNo or
enclose the field name in brackets, i..e [strFile#].SetFocus
Also make sure the control is Enabled.
 

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