PDA

View Full Version : Option Buttons



wikush
02-21-2005, 04:14 AM
I have two option buttons on a form in Microsoft Access 2000. I want one of them to be selected automatically when the form loads up. Now I thought it would be the same code you would use in vb like optTest.value = true, but now that looks like it doesnt work in VBA. I get a Runtime Error "2448" You cant assign a value to this object. So how do you set the option button to being selected then??:banghead:

Killian
02-21-2005, 04:43 AM
If my memory serves me well (which it may not) the property you need is "Default Value" which you can set with the form in design mode rather than doing it on the load event which might be easier.

TonyJollans
02-21-2005, 04:46 AM
I'm not sure whether this is exactly what you're after but you can make one of the buttons on a Form the default (i.e. the button that will, by default, be selected if Enter is pressed) by setting the Default property (under Other in the properties box) to Yes.

TonyJollans
02-21-2005, 04:47 AM
Snap!

wikush
02-21-2005, 04:59 AM
Thanks but it's not quite what I want. Is there a way where I can set it in code and not on the properties screen.

TonyJollans
02-21-2005, 06:07 AM
In code you can set Me.ButtonName.Default = True.
I'm not sure off the top of my head but I don't think you can change it once the Form is displayed but you should be alright setting it when you first display the form.

AlanG
02-27-2005, 07:05 AM
Hi

Don't know if this what you're looking for, but if your buttons are radio buttons within an option group, you can set which one is the default programatically like this

Private Sub Form_Open(Cancel As Integer)
Me.optTest.DefaultValue = 1
End Sub

where Me.optTest is the name of your option group, and the number is the value of the radio button you want as the default

HTH

Alan

Imdabaum
07-28-2006, 11:12 AM
Private Sub cmdbuildingSearch_Click()
On Error GoTo Err_cmdbuildingSearch_Click
If Me.SearchOption.Value = 2 Then
Me.Title.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
Else
Me.BuildingID.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
End If
Exit_cmdbuildingSearch_Click:
Exit Sub
Err_cmdbuildingSearch_Click:
MsgBox Err.Description
Resume Exit_cmdbuildingSearch_Click

End Sub

Anyone know why this code would make the Find option not work? From what I am aware the Find menu gets the operation from what field has the focus. So By creating options of which value to search for, I set the focus and perform the search. Unfortuanely, I everytime I run it, I get an Error : 2046: The command or action 'Find' isn't available now.

AMMENDMENT: When I stopped trying to step through it to verify proper OptionGroup values, it worked fine. For some reason it didn't like me stepping calling the function from Debug mode.

CFDM
09-06-2006, 03:07 PM
USE THE WIZARD

Imdabaum
09-07-2006, 06:58 AM
USE THE WIZARD

Well the solution to my problem was running that command during step through debugging. For some reason it does not allow you to run that command while stepping through the code. But I suppose the wizard would be a good way to do ii if you aren't sure how to program it.

CFDM
09-07-2006, 07:39 AM
obviously you DIDN'T KNOW HOW TO PROGRAM IT YOURSELF- if you asked the question

Imdabaum
09-07-2006, 07:42 AM
I wasn't trying to offend. The programming was right just the execution mode caused the problem.