option button (able to be clicked and displayed the user choice)

  • Thread starter sulaiman chang via AccessMonster.com
  • Start date
S

sulaiman chang via AccessMonster.com

hi all,
i am sulaiman from malaysia.
i need some help regarding Ms Access option button.

let say i have a database structure like below :

id -----------> data type
bGender ------> byte

and let say the form have 2 option buttons.
one is Male and another one is Female.

( ) Male ( ) Female

let say in the form also got a textbox [___________] which would store the
gender value, 0 equal to Male and 1 equal to Female.

and i wish the option button would be automatically checked based on the
textbox value (once the record is displayed or when user press the next or
back from the default data control), if textbox value is 0, then the (*)
Male should be checked and ( ) no check in Female.

let say if the user checked on option male, then the male option box must
be checked and the value of the textbox must be change to "0"...

i am having the problem to "TRAP" the acNext event. could your guys give me
some ideas ?


sincerely,
sulaiman chang
 
S

sulaiman chang via AccessMonster.com

Code:
Private Sub Form_Current()
If bJantina.Value = 0 Then
optLelaki.Value = 1
optPerempuan.Value = 0
Else
optLelaki.Value = 0
optPerempuan.Value = 1
End If
End Sub
 
S

sulaiman chang via AccessMonster.com

"sorry", i can't edit back previous post

the above example look fine but the problem it, it would create additional
empty record once the user scroll their mouse or clicking the next button
on the default data control.
 
S

sulaiman chang via AccessMonster.com

sorry, just figure out
i just need to set the default value of the bJantina to 2 or other to
prevent it insert new record :p

Private Sub Form_Current()
If bJantina.Value = 0 Then
optLelaki.Value = 1
optPerempuan.Value = 0
ElseIf bJantina.Value = 1 Then
optLelaki.Value = 0
optPerempuan.Value = 1
End If
End Sub
 
S

sulaiman chang via AccessMonster.com

Private Sub Form_Current()
If bJantina.Value = 0 Then
optLelaki.Value = True
optPerempuan.Value = False
ElseIf bJantina.Value = 1 Then
optLelaki.Value = False
optPerempuan.Value = True
End If
End Sub

Private Sub optLelaki_Click()
optLelaki.Value = True
optPerempuan.Value = False
bJantina.Value = "0"
End Sub

Private Sub optPerempuan_Click()
optPerempuan.Value = True
optLelaki.Value = False
bJantina.Value = "1"
End Sub

yup, this is solving my problem :)
just understand what is the difference between VALUE property and TEXT
property.


[quote from : VBA help file]
The Text property returns the formatted string. The Text property may be
different than the Value property for a text box control. The Text property
is the current contents of the control. The Value property is the saved
value of the text box control. The Text property is always current while
the control has the focus.
 
R

Rob Oldfield

Glad you got it working, but....

You're better off using an option group with two option buttons, which has
all this functionality already built in.

sulaiman chang via AccessMonster.com said:
Private Sub Form_Current()
If bJantina.Value = 0 Then
optLelaki.Value = True
optPerempuan.Value = False
ElseIf bJantina.Value = 1 Then
optLelaki.Value = False
optPerempuan.Value = True
End If
End Sub

Private Sub optLelaki_Click()
optLelaki.Value = True
optPerempuan.Value = False
bJantina.Value = "0"
End Sub

Private Sub optPerempuan_Click()
optPerempuan.Value = True
optLelaki.Value = False
bJantina.Value = "1"
End Sub

yup, this is solving my problem :)
just understand what is the difference between VALUE property and TEXT
property.


[quote from : VBA help file]
The Text property returns the formatted string. The Text property may be
different than the Value property for a text box control. The Text property
is the current contents of the control. The Value property is the saved
value of the text box control. The Text property is always current while
the control has the focus.
 
S

sulaiman chang via AccessMonster.com

thanks rob for your reply,
:p
i would try to use it next time :)
but the option group is displaying a frame when it displays those option
buttons. is that anyway to use the option group but without displaying the
option group frame?
 
D

Dirk Goldgar

sulaiman chang via AccessMonster.com said:
thanks rob for your reply,
i would try to use it next time :)
but the option group is displaying a frame when it displays those
option buttons. is that anyway to use the option group but without
displaying the option group frame?

An option frame's Border Style property can be set to Transparent, and
the associated label can be deleted.
 

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