Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change an option group value to null? 1

Status
Not open for further replies.

ottograham

Technical User
Mar 30, 2001
109
US
I'm a new user - please bear with me.

I have a form with 20 yes/no option groups. Occasionally a user will need to change a value already selected back to null. How do you write the code to generically assign the value of the field to null (i.e. one function could be used for all 20 fields).

Thanks for any help you can offer.

Scott
 
Hello OttoGraham!

As an option group may contain check boxes,toggle buttons or others, their values are usually set i.e. 1,2,3. The option group its self is holding the value. In order to set it to Null I'm using the "Double-click" event of the option group its self.

In the Double-click event for each option group that requires this feature, in Visual Basic (Each option group properties - Events tab - On Dbl Click, select "Event Procedure", click "..." beside to open Visual Basic and automatically label a sub) type in between the title label and "end sub":

MakeItNull

Now copy/paste this "Private Sub" into the same module anywhere on its own. (Not within another sub):

Private Sub MakeItNull()
On Error GoTo ErrMIN
Dim ctl As Control
Set ctl = Me.ActiveControl
Me.ActiveControl = Null

ExitMIN:
Exit Sub

ErrMIN:
MsgBox Err.Number & " " & Err.Description, vbInformation, "Make it Null error."
Resume ExitMIN
End Sub

Close and save and give it a go. Remember you are double-clicking on the option group, not the checks or toggles, and it will work better if you have a backcolor for each toggle group even if it is the same color as the form. Alternatively, you could add a command button beside each group that would do the same in its "on click" event. Bingo! :) Gord
ghubbell@total.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top