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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Default value

Status
Not open for further replies.

Onslaughtdave

Programmer
Jan 24, 2005
59
CA
Hi,

Is there a way to make an option group display the value that it connects to...

i mean:

in a table you have 2 records, yes and no.

in a form you have a option button group with yes and no...
is their a way to get them to look that up and display that.

on the form it looks like this:
(.) yes
() no

can you make it change to reflect the current record?

cheers,

dave
 
Take a look at the Current event of the form.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Your question is a bit hard to follow, but are you trying to bind the option group to a Yes/No field?

If so all you need to do is add a Frame to the form, and then place 2 Option Buttons inside the frame. Then bind the Frame to the Yes/No field (set its ControlSource to the field name). Set one Option Button's "Option Value" to -1 for True, and the other Option Button's "Option Value" to 0 for False.

If you aren't trying to bind to a field, then you don't need to use a "Default Value" since you can just set the value of the Frame in the Form_Current() event. The only reason to use a "Default Value" is when when you start a new record, and you want to autofill certain fields without committing them, allowing the user to cancel the record if needed.



VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
Here is my actual situation:

There are 3 possible options: regular, relief, other

when u select one it buts one of the above in the table...how do i get it to read the table and activate the option that is in the table.

option buttons originally put 1,2,3 into the table and i change it right after...

thanks,

dave
 
Leave the frame unbound and Load/Save the values in code:
Code:
Private Sub Form_Current()
  If Not Me.NewRecord Then
    LoadOptionGroup
  End If
End Sub

Private Sub fraOptions_AfterUpdate()
  SaveOptionGroup
End Sub

Private Sub LoadOptionGroup()
  Select Case Me![OptionText]
    Case "Regular"
      Me!fraOptions.Value = 1
    Case "Relief"
      Me!fraOptions.Value = 2
    Case "Other"
      Me!fraOptions.Value = 3
  End Select
End Sub

Private Sub SaveOptionGroup()
  Select Case fraOptions.Value
    Case 1
      Me![OptionText] = "Regular"
    Case 2
      Me![OptionText] = "Relief"
    Case 3
      Me![OptionText] = "Other"
  End Select
End Sub
Leave the option buttons' values at 1,2,3, and set the default value of the frame to 1, which in this example is "Regular"
[tt]
+--fraOptions-------------+
| |
| (.) Regular - 1 |
| |
| ( ) Relief - 2 |
| |
| ( ) Other - 3 |
| |
+-------------------------+
[/tt]

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
You'll also need to update the field in the Form_BeforeUpdate() event for cases when the user accepts the default value without clicking the option button. You can set the default value in the Form_Current() event as well:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
  SaveOptionGroup
End Sub

Private Sub Form_Current()
  If Not Me.NewRecord Then
    LoadOptionGroup
  Else
    [blue]Me!fraOptions.DefaultValue = 1[/blue]
  End If
End Sub


VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
Hey VB, are you now employed? Your handle used to say unemployed in Houston. If so, congratulations!

Have a great day!

j2consulting@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top