Option Group

G

Guest

I've created an option group with 2 options: Cash and Cheque. I have an
update query such that when Cash is checked, it would update the field called
strPayMode to Cash. However, I couldn't get the option group to display the
options correctly for existing records. How do I get the option group to show
Cash (option 1) as checked when the strPayMode field says Cash? I tried
something like this in the Form Current property but it didn't work:

If strPayMode = "Cash" Then
opgPayMode = 1
ElseIf strPayMode = "Cheque" Then
opgPayMode = 2
End If

Am I doing this correctly? Thanks.
ck
 
F

fredg

I've created an option group with 2 options: Cash and Cheque. I have an
update query such that when Cash is checked, it would update the field called
strPayMode to Cash. However, I couldn't get the option group to display the
options correctly for existing records. How do I get the option group to show
Cash (option 1) as checked when the strPayMode field says Cash? I tried
something like this in the Form Current property but it didn't work:

If strPayMode = "Cash" Then
opgPayMode = 1
ElseIf strPayMode = "Cheque" Then
opgPayMode = 2
End If

Am I doing this correctly? Thanks.
ck

No, you are not doing it correctly.
All you need do is have the Option Group control bound to a field
(strPayMode, which should be a Number, Integer datatype field) in the
table (by setting the Option Group ControlSource to that field).
When you select the Cash radio button, it's value (a Number) is saved
automatically (without any additional code or Update query needed) in
the table. When you navigate through the records, each record will
then show Cash or Cheque button as stored in that record.

While the saved value is a number, it is easy enough, in a report, or
wherever, to display a text equivalent , using an IIf(), or Choose()
function, or a Select Case statement.
Here is the IIF() with just 2 choices:

=IIf([strPayMode] = 1,"Cash","Cheque")
 
G

Guest

Rather than store the literals 'Cash' and 'Cheque' on the table, I would
recommend that you store the values 1 or 2. You would do this by binding the
option group to the appropriate column. Then, the correct option would be
'ticked' when scrolling through existing rows. without having to put any code
in the form's Current eventHandler.

Hope This Helps
Gerald Stanley MCSD
 
G

Guest

Thanks fredg. I never thought of storing a value rather than the text. Thanks
for the tip! I'll change it right away.
ck

fredg said:
I've created an option group with 2 options: Cash and Cheque. I have an
update query such that when Cash is checked, it would update the field called
strPayMode to Cash. However, I couldn't get the option group to display the
options correctly for existing records. How do I get the option group to show
Cash (option 1) as checked when the strPayMode field says Cash? I tried
something like this in the Form Current property but it didn't work:

If strPayMode = "Cash" Then
opgPayMode = 1
ElseIf strPayMode = "Cheque" Then
opgPayMode = 2
End If

Am I doing this correctly? Thanks.
ck

No, you are not doing it correctly.
All you need do is have the Option Group control bound to a field
(strPayMode, which should be a Number, Integer datatype field) in the
table (by setting the Option Group ControlSource to that field).
When you select the Cash radio button, it's value (a Number) is saved
automatically (without any additional code or Update query needed) in
the table. When you navigate through the records, each record will
then show Cash or Cheque button as stored in that record.

While the saved value is a number, it is easy enough, in a report, or
wherever, to display a text equivalent , using an IIf(), or Choose()
function, or a Select Case statement.
Here is the IIF() with just 2 choices:

=IIf([strPayMode] = 1,"Cash","Cheque")
 
G

Guest

Thanks, Gerald. Like I replied to an earlier response, I never thought of
storing a value instead of the actual text. I'll change the option group
accordingly.
ck
 

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