Passing option group value to vba function

M

Muscat.Angelo

I'm sure I've done this before but can't for the life of me figure it
out now, and hours of research online haven't helped. I'm simply
trying to pass an option group value from a form to a vba function.
I'd like the user to choose option1 or option2 and when they click a
button, the function will run an if statement like "if
option1.value=true then...."

I've got 2 options named option1 and option2 and a frame called
frame20, what else do I need? I've also tried bounding the selection
to a textbox, but keep getting errors. Any help on the process?

Thanks,
Angelo
 
A

Allen Browne

If you set up the function as below, you can call it like this:
Call MyFunc(Me.frame20)

Function MyFunc(grp As OptionGroup)
Select case grp.Value
Case 1
MsgBox "Option value is 1."
Case 2
MsgBox "Option value is 2."
Case Else
MsgBox "Huh?"
End Select
End Function
 
D

Dale Fye

Angelo,

The frame has an AfterUpdate event and it also has a value property You can
can call your function from the afterupdate event of the frame (option group)
and pass it the value, something like:

private sub og_YourOptionGroup_AfterUpdate

Call YourFunction(me.og_YourOptionGroup)

End Sub

If the value of the option group is linked to a field in your database, you
will probably also want to call this function from the Current event of your
form.

HTH
Dale
 

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