Options Group??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi! I'm trying to prepare a Form (about Quotation=prices) so that I can fill a table with the following information:
I may choose between DOLLAR and REAL. If I choose DOLLAR, 3 fields will have to be filled. They are: unit price in dollar, dollar tax(real-dollar)land unit price in real(calculated based on previous ones). BUT if I choose REAL, only one field will have to be filled. It is unit price in real. In summary I need to inhibit the fields to be filled for DOLLAR when I choose REAL, and vice-versa.
If there is someone to help me, please, make any contact to me. Thank you very much!
 
In the AfterUpdate event of the option group and the Form's Current event
(to catch this when you move to existing records) check the value of the
option group and enable/disable the controls as appropriate.

Example:
If Me.optNameOfOptionGroup = 1 Then
Me.txtTextbox1.Enabled = False
Me.txtTextbox2.Enabled = False
Else
Me.txtTextbox1.Enabled = True
Me.txtTextbox2.Enabled = True
End If

If you have more than 2 options, it may be easier to use a Select Case
statement then to keep stringing Ifs together. You may also want to play
with combinations of the Enabled and Locked properties, depending on how you
want the controls to look and act.

--
Wayne Morgan
Microsoft Access MVP


Andrea Duran said:
Hi! I'm trying to prepare a Form (about Quotation=prices) so that I can
fill a table with the following information:
I may choose between DOLLAR and REAL. If I choose DOLLAR, 3 fields will
have to be filled. They are: unit price in dollar, dollar
tax(real-dollar)land unit price in real(calculated based on previous ones).
BUT if I choose REAL, only one field will have to be filled. It is unit
price in real. In summary I need to inhibit the fields to be filled for
DOLLAR when I choose REAL, and vice-versa.
If there is someone to help me, please, make any contact to me. Thank you
very much!
 
Andrea,

Sure. You can do this with an Option Group. If you have not already
created it, use the control wizard in your form's design view to create the
Option Group. When you enter the Label Names, enter Dollar first and then
Real. Accept the Wizard's suggestion to make Dollar your default choice.
Accept the Wizard's suggestion to make the Option Values: Dollar = 1 and
Real = 2. Accept the remaining Wizard prompts/suggestions by clicking Next.
Then click Finish to save the control on your form

Now you are ready to add a bit of code to enable or disable controls on your
form depending on the option selected:

1. Right click on the Option Group control (not either of its values) and
select Properties.

2. When the Properties sheet opens, click the tab labeled Event.

3. In the grid below, locate the row labeled, After Update. It should be
blank. Click anywhere in the white space to the right of the label and you
will see a downward-pointing arrow appear, indicating that this is also a
ComboBox. Click the arrow and select "Event Procedure".

4. Then, notice that there is an ellipsis or three little dots (...) to the
right of the ComboBox. Click the ellipsis and you will open a code window.
You will see that Access has given you a space for entering some code in
this event - it will look something like the following:

Private Sub YourControlName_AfterUpdate(Cancel As Integer)

End Sub

5. After the "Private Sub YourControlName_AfterUpdate(Cancel As Integer)"
line, insert the following code:

If Me!YourControlName = 2 then
Me![unit price in dollar].Enabled = False
Me![dollar tax].Enabled = False
Else
Me![unit price in dollar].Enabled = True
Me![dollar tax].Enabled = Trye
End If


Using the Enabled property turns the controls "gray", giving the user a
visual cue that they are disabled. You can also use the Locked property, if
you desire.

Give this a try and please post back to this thread if you have any
follow-up questions.
--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


Andrea Duran said:
Hi! I'm trying to prepare a Form (about Quotation=prices) so that I can
fill a table with the following information:
I may choose between DOLLAR and REAL. If I choose DOLLAR, 3 fields will
have to be filled. They are: unit price in dollar, dollar
tax(real-dollar)land unit price in real(calculated based on previous ones).
BUT if I choose REAL, only one field will have to be filled. It is unit
price in real. In summary I need to inhibit the fields to be filled for
DOLLAR when I choose REAL, and vice-versa.
If there is someone to help me, please, make any contact to me. Thank you
very much!
 
Hi Cheryl!
Your explanation was clear and full of details, but the problem is that for the fisrt part:

"When you enter the Label Names, enter Dollar first and then
Real. Accept the Wizard's suggestion to make Dollar your default choice.
Accept the Wizard's suggestion to make the Option Values: Dollar = 1 and
Real = 2. Accept the remaining Wizard prompts/suggestions by clicking Next.
Then click Finish to save the control on your form"

I message comes up on screen telling me this "resource in not installed". So as I don't have how to reinstall it by now, after clicking on Option Group bottom on the tools bar, the message i've mentioned appeared, I ignored it by closing and started filling forms by right clicking on "properties".
1)FORM Label: Label Dollar
Name: Label Dollar
Label: Dollar
Visible: Yes
Show when: always
.....
2)FORM Option Group: Dollar
Name: Dollar
Control Origin: ?? selected from the available tables or make an expression?
Pattern Value: 1
.....
Visible: Yes
Show when: always
.....
AfterUpdate:[Event Procedure] ...(your suggsested coding OK)
.....

Then I've clicked on Option Group bottom again and did the same for REAL!?

By your explanation I understood that this assistent creates Dollar as defaut option, and Real as a second option under the same option group. I fell I did it wrong, but I didn't find a good way to follow your steps without using the assistent.

As a result I have on my screen: a box on which is written Dollar over another empty box, and the same for Real. Nothing related to thecoding I've programmed appears on this empty box.

Could you still help me?!
Thanks anyway and regards,
Andrea.
NOTE: my ACCESS in not in English, so my translation may differ from the original ACCESS on the explanation above!
 
Andrea,

It sounds as if you do not have the Wizards installed - and I can see how
the instructions I provided would not make much sense without them!
However, it should not be too difficult to create your Option Group without
the wizards:

1. Drag an Option Group control onto your form and open its Properties
sheet. Click the tab labeled 'Data'. At this point, we are concerned only
with the first two properties listed under the 'Data' tab, Control Source
(Control Origin) and Default Value (Pattern Value), respectively:

Control Source (Control Origin): this is the name of a field in the
table or query which is the record source for your form. If you want to
record the choice you make in the Option Group in a field, then you should
insert the name of that field here.

Default Value (Pattern Value): Enter a 1 here

2. Now, you will need to select an Option Button from the toolbar and drop
it into the Option Group you have just created. The "dot" and an
associated label should appear within the Option Group box. Open the
Properties sheet for this button and click the 'Data' tab. The first
property shown, Option Value, should be 1 because this is the first option
placed within the group. Close the Properties sheet. Now, just modify the
label that is associated with this Option Button to say "Dollar".

Then, select and drag a second Option Button from the toolbar and drop it
into the Option Group. Open the Properties sheet for this button, click
the 'Data' tab and observe the first property listed. Option Value for this
button should be 2. Close the Properties sheet and then modify the label
associated with this Option Button to say "Real".

3. Last, right-click on the Option Group and insert the code provided
earlier.

See how this works, Andrea, and let us know.

--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


Andrea Duran said:
Hi Cheryl!
Your explanation was clear and full of details, but the problem is that for the fisrt part:

"When you enter the Label Names, enter Dollar first and then
Real. Accept the Wizard's suggestion to make Dollar your default choice.
Accept the Wizard's suggestion to make the Option Values: Dollar = 1 and
Real = 2. Accept the remaining Wizard prompts/suggestions by clicking Next.
Then click Finish to save the control on your form"

I message comes up on screen telling me this "resource in not installed".
So as I don't have how to reinstall it by now, after clicking on Option
Group bottom on the tools bar, the message i've mentioned appeared, I
ignored it by closing and started filling forms by right clicking on
"properties".
1)FORM Label: Label Dollar
Name: Label Dollar
Label: Dollar
Visible: Yes
Show when: always
...
2)FORM Option Group: Dollar
Name: Dollar
Control Origin: ?? selected from the available tables or make an expression?
Pattern Value: 1
...
Visible: Yes
Show when: always
...
AfterUpdate:[Event Procedure] ...(your suggsested coding OK)
...

Then I've clicked on Option Group bottom again and did the same for REAL!?

By your explanation I understood that this assistent creates Dollar as
defaut option, and Real as a second option under the same option group. I
fell I did it wrong, but I didn't find a good way to follow your steps
without using the assistent.
As a result I have on my screen: a box on which is written Dollar over
another empty box, and the same for Real. Nothing related to thecoding
I've programmed appears on this empty box.
Could you still help me?!
Thanks anyway and regards,
Andrea.
NOTE: my ACCESS in not in English, so my translation may differ from the
original ACCESS on the explanation above!
 
Cheryl, it seems I follow your steps regarding to Control Source and Default Value, the names of the option bottoms and I also checked the values already set. For Control Source I have a field defined an number of one digit to set the information 1(Dollar) or 2(Real) from the refer. table.
I have to do some ajustments on my reference table too

I changed the code to swap between fields for Dollar and fields for Real, this way
Private Sub Moldura24_AfterUpdate(
If Me!Moldura24 = 2 The
Me![Taxa do Dólar].Enabled = False {Dollar Tax
Me![Preço Unitário em Dólar].Enabled = False {Unit Price in Dollar
Me![Preço Total em Dólar].Enabled = False {Total Price in Dollar-calculated base on Unit Price and Quantity of the item
Me![Preço Unitário Convertido para Real].Enabled = False {Unit Price Converted to Real -calculated based on Dollar Tax and Unit Price
Me![Preço Total Convertido para Real].Enabled = False {Total Price Converted to Real -calculated base in Dollar Tax and Total Price
Me![Preço Unitário em Real].Enabled = True {Unit Price in Real
Me![Preço Total em Real].Enabled = True {Total Price in Real-calculated base on Unit Price and Quantity of the item
Els
Me![Taxa do Dólar].Enabled = Tru
Me![Preço Unitário em Dólar].Enabled = Tru
Me![Preço Total em Dólar].Enabled = Tru
Me![Preço Unitário Convertido para Real].Enabled = Tru
Me![Preço Total Convertido para Real].Enabled = Tru
Me![Preço Unitário em Real].Enabled = Fals
Me![Preço Total em Real].Enabled = Fals
End I
End Su

But I did some tests and saw some problems I couldn't solve
1) Starting with my first Register on the form, I pressed Dollar(option bottom inside my option group) that was already marked, and the fiels that should inhibit were not inhibited(it means those fields related to values directly in Real). I can fill up all of them
2) If I press Real, the correct fiels get inhibited, but if I don't fill them up and decide to press Dollar, so, then, the correct fields get inhibited fo Dollar option
3) If my previous register was for Real option, my next register to be filled comes up with the option Dollar pressed, but with the fields related to Dollar inhibited, and those related to Real activated- it seems that it kept the last value from the previous register on the variable
And even if I press Dollar the fields remain the same way

Another thing is that the fields that results from a calculation doesn't appears on the refer. table. Only the fields I type go to the table- is that the way it should be?

I've changed someway the procedure but I guess the fields related were correctly filled. Do you have
any suggestion for me to correct it?! Thanks anyway, Andrea.
 
Andrea,

In order to have the proper fields enabled or disabled as you move from
record to record, you will also need to add your code to the Form's On
Current event. This is the first event listed on the property sheet for the
Form.
Another thing is that the fields that results from a calculation doesn't
appears on the refer. table. Only the fields I type go to the table- > is
that the way it should be?

If your calculation uses data that you enter on the form, you will need to
write some code to assign the value of the calculation to the field/control.
Generally, you would use the After Update event for the controls which
contain the data used in the calculation.


--
Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


Andrea Duran said:
Cheryl, it seems I follow your steps regarding to Control Source and
Default Value, the names of the option bottoms and I also checked the values
already set. For Control Source I have a field defined an number of one
digit to set the information 1(Dollar) or 2(Real) from the refer. table.
I have to do some ajustments on my reference table too.

I changed the code to swap between fields for Dollar and fields for Real, this way:
Private Sub Moldura24_AfterUpdate()
If Me!Moldura24 = 2 Then
Me![Taxa do Dólar].Enabled = False {Dollar Tax}
Me![Preço Unitário em Dólar].Enabled = False {Unit Price in Dollar}
Me![Preço Total em Dólar].Enabled = False {Total Price in
Dollar-calculated base on Unit Price and Quantity of the item}
Me![Preço Unitário Convertido para Real].Enabled = False {Unit Price
Converted to Real -calculated based on Dollar Tax and Unit Price}
Me![Preço Total Convertido para Real].Enabled = False {Total Price
Converted to Real -calculated base in Dollar Tax and Total Price}
Me![Preço Unitário em Real].Enabled = True {Unit Price in Real}
Me![Preço Total em Real].Enabled = True {Total Price in
Real-calculated base on Unit Price and Quantity of the item}
Else
Me![Taxa do Dólar].Enabled = True
Me![Preço Unitário em Dólar].Enabled = True
Me![Preço Total em Dólar].Enabled = True
Me![Preço Unitário Convertido para Real].Enabled = True
Me![Preço Total Convertido para Real].Enabled = True
Me![Preço Unitário em Real].Enabled = False
Me![Preço Total em Real].Enabled = False
End If
End Sub

But I did some tests and saw some problems I couldn't solve:
1) Starting with my first Register on the form, I pressed Dollar(option
bottom inside my option group) that was already marked, and the fiels that
should inhibit were not inhibited(it means those fields related to values
directly in Real). I can fill up all of them.
2) If I press Real, the correct fiels get inhibited, but if I don't fill
them up and decide to press Dollar, so, then, the correct fields get
inhibited fo Dollar option.
3) If my previous register was for Real option, my next register to be
filled comes up with the option Dollar pressed, but with the fields related
to Dollar inhibited, and those related to Real activated- it seems that it
kept the last value from the previous register on the variable.
And even if I press Dollar the fields remain the same way.

Another thing is that the fields that results from a calculation doesn't
appears on the refer. table. Only the fields I type go to the table- is
that the way it should be?
 
Back
Top