You are VERY close. Yes, your process was correct. I suspect that Access
hasn't tumbled to the fact that there is code associated with that frame.
Here's how to check/fix it.
a) Open the form in design view.
b) Click on the line that defines the frame box (not the associated frame
label box with the text SortBy in it, but the box that encompasses the option
buttons.)
c) Click on the PROPERTIES button on the menu bar. (alternate method -
right-click on the frame box and then select PROPERTIES from the drop down.
d) Click on the EVENTS tab.
e) Scroll down - find OnClick
At this point there should be
[Event Procedure]
in that line. Probably isn't. It is a drop down, so
(f) at far right, click and select [EVENT PROCEDURE]
g) Just to the right you will see a button for this current line only with
"..." - Click it.
It will open the VBA editor positioned to the OnClick event for the frame.
It should be filled in with your version of my code.
I have seen situations where Access doesn't realize that there is code bound
to an event unless you put it there via this sequence. Don't know why. So
coming in via this sequence may very well resolve the problem.
If you do NOT have code there, it means that you have an inconsistency in
the name of the control versus the name of the event. The event proc for the
click event is controlname_Click, so you should have
Private Sub frame21_Click()
-----
Click DEBUG on main menu bar.
Click COMPILE to make sure that everything is syntactically correct.
Save, close VBA, close design view and test.
----
While we are at it - if you get to the properties page for a control and
select the ALL tab, and then scroll to the very top line - that's the name of
the control. You could then change it to 'frame_SortBy'. Note that this
really should be done before you add code as renaming it will NOT rename the
event SUBs associated with the control.
-------
Another trick: In the VBA window, at the top of the frame, are two drop
downs. The left one has GENERAL at the top of the list, and then within the
list are the various controls on the form, sections, the form itself, etc.
All things that can have code associated. If you select a control, then the
right dropdown shows all of the possible events for that control. Those with
code are in bold. Now a trick - select GGENERAL. The right drop down will
list any procs (funcions or subroutines) that are NOT associated with a
control, section, etc. If you see something liike 'fram_21' it means that it
is a proc that isn't associated with a control. That's perfectly OK as you
can write helper routines to do stuff etc. that you call from whithin events.
But in my example, it is more likely to be a typo in the name of the routine
that needs investigating.
I'll check back in tomorrow and after -it's 9:30PM Friday here.
Ted M H said:
Hi NK,
Thanks for hanging with me on this. Your efforts are much apprecieated.
Initially I used the control wizard to set up the frame and option buttons.
This time I turned off the wizard and created the frame. A frame is created
by using the Option Group control tool, correct? If there's a tool somewhere
called a Frame tool, I can't find it.
Access assigned the name to my frame: Frame21, and I could not find any way
to change the name to SortBy. I've changed the caption for the label to
SortBy, but that isn't going to help, is it?
I added the radio buttons one at a time and checked that their option values
are 1, 2 and 3. The frame went black when I added each radio button, so that
must mean they are subservient to the frame.
When I try to add the code as an event procedure, the VBA editor comes up
with this:
Option Compare Database
Private Sub Frame21_Click()
End Sub
I then paste in your code so it looks like this:
Option Compare Database
Option Explicit
Private Sub frame_Frame21_Click()
Select Case frame_Frame21
Case 1:
Me.OrderBy = "[Namex]"
Case 2:
Me.OrderBy = "[Rank]"
Case 3:
Me.OrderBy = "[SerialNumber]"
End Select
End Sub
I'm using the field name Namex instead of name because Access 2007 won't
allow me to name a field in my table Name--says it's reserved by the system.
When I click on the radio buttons nothing happens. Likewise, when I insert
the break point in the code and click the buttons, nothing happens. I
suspect the problem has something to do with the frame name and the Private
Sub statement. Can you provide additional guidance?
Many thanks.
NKTower said:
Let's go back to my example (Name, Rank, SerialNumber)
Things you might have wrong...
#1 - When you created the radio buttons, did you EDIT /DUPLICATE the first
to make the 2nd and 3rd? If so, they alll have the same associated value.
Right click on each and make certain that they are 1,2,3 respectively
#2 - when you created the radio buttons, the inside of the frame that they
are in should have gone "black" when you were about to drag-and-drop them in.
Did it? If not, then the buttons aren't subservient to the frame.
#3 - Are you sure that the code is in the frame's OnClick event? To check
to see if it is firing, open the code window and click on the gray bar left
margin of the code window. Click immediately to the left of the SELECT CASE
statement. You shold get a red dot in the gray bar. This is a break point.
Save the form. Run it. When you click a radio button, the code will stop at
the break point. If it doesn't, you aren't executing the code. Press F5 to
continue.