Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

If two options are "True" then...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Newforms - 28 Sep 2006 00:34 GMT
Hi, I am trying to put togther a form that populates a Word document,
the idea is this:

Bread: $50
Cheese: $20
Milk: $10

Total: $80

I want to have options that can be selected so that the total changes
as required, so that if only bread and cheese are selected the total is
$70.

The code I have so far is this:

Dim mytext As String
If OptionButton1.Value = True Then
   bread = "Bread - $50"
ElseIf OptionButton2.Value = True Then
   cheese = "Cheese - $20"
ElseIf OptionButton3.Value = True Then
   milk = "Milk - $10"
End If

I am trying to include code to determine what options are true and
produce the correct total. Any ideas?

Thanks, Jonathan

PS. I know these are very expensive groceries, its just to illustrate
the point! ;)
Tony Strazzeri - 28 Sep 2006 04:00 GMT
The problem with the code you are using is that it will fall out of the
test as soon as ANY of the the tests are true.

Try defining a variable to hold the total and add to it each of the
amount for the true options.

BTW I am not sure what you are actually trying to do with the variables
called bread, cheese, milk since thay appear to be labels and not
values.
ig
dim lTot as long

lTot=0
dim sTape as string

If OptionButton1.Value = True
This can be simplified as "If OptionButton1 Then"  since true is the
default value.

try this.
If OptionButton1 Then
  iTot=iTot+50   'Bread
  sTape=sTape & vbcr & "Bread - $50"
endif

If OptionButton2 then
  iTot=iTot+20
  sTape=sTape & vbcr & "Cheese - $20"
endif

If OptionButton3 then
  iTot=iTot+10
  sTape=sTape & vbcr & "Milk - $10"
endif

msgbox sTape & vbcr & "========" & vbcr & "Total " & iTot

Of course this can be further simplified by using descriptive names for
the option buttons (eg "obBread") and/or arrays to hold the label and
amount for each option button.  Post your code back for suggestions
once you have the process working.

Cheers
TonyS.

> Hi, I am trying to put togther a form that populates a Word document,
> the idea is this:
[quoted text clipped - 27 lines]
> PS. I know these are very expensive groceries, its just to illustrate
> the point! ;)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.