PDA

View Full Version : Vba help



liam1289
08-18-2010, 09:49 AM
i am trying to make a calculation. i have 2 options boxes and 2 checkboxes. both in different frames. when one option box is selected the other frame is disbaled. but if the other option is selected you have to choose a checkbox. when check boxes are checked singley they add up correctly but when 2 are selected it doesnt work
.the code i have used is


Private Sub CmdCalculate_Click()
Dim card As Double
Dim cost As Double

If optmedcard = True Then
msg = "No Charge to card holders!"
Buttons = vbInformation
Title = "Medical Card Holder"
MsgBox msg, Buttons, Title
End If
If optmedno = True And chkcalout = False And Chkstandard = False Then
msg = "Please Select Option from the other frame"
Buttons = vbInformation
Title = "Not a Card Holder"
MsgBox msg, Buttons, Title
End If


If chkcalout = True Then
card = card + 15
End If
If Chkstandard = True Then
cost = cost + 35
End If

If chkcalout = True Then
msg = "Callout Cost = " & card & vbCrLf & "Cost = " & cost & vbCrLf & "Total Order =" & (15 + Chkstandard)
Buttons = vbInformation
Title = "Total Cost"
MsgBox msg, Buttons, Title

ElseIf Chkstandard = True Then
msg = "Standard Cost = " & card & vbCrLf & "Card = " & cost & vbCrLf & "Total Order =" & (chkcalout + 35)
Buttons = vbInformation
Title = "Total Cost"
MsgBox msg, Buttons, Title

ElseIf Chkstandard And chkcalout = True Then
msg = "Standard Cost = " & card & vbCrLf & "Card = " & cost & vbCrLf & "Total Order =" & (15 + 35)
Buttons = vbInformation
Title = "Total Cost"
MsgBox msg, Buttons, Title
End If

End Sub

Private Sub cmdexit_Click()
msg = "Are you sure you want to exit?"
Buttons = vbYesNo + vbDefaultButton2
Title = "Exiting Westdoc System"
Reply = MsgBox(msg, Buttons, Title)
If Reply = vbYes Then
End
End If
End Sub


Private Sub optmedcard_Click()
Frame2.Enabled = False


End Sub

Private Sub optmedno_Click()
Frame2.Enabled = True


End Sub

Bob Phillips
08-18-2010, 10:40 AM
Logical order!



Private Sub CmdCalculate_Click()
Dim card As Double
Dim cost As Double

If optmedcard = True Then
msg = "No Charge to card holders!"
Buttons = vbInformation
Title = "Medical Card Holder"
MsgBox msg, Buttons, Title
End If
If optmedno = True And Chkcalout = False And ChkStandard = False Then
msg = "Please Select Option from the other frame"
Buttons = vbInformation
Title = "Not a Card Holder"
MsgBox msg, Buttons, Title
End If


If Chkcalout = True Then
card = card + 15
End If
If ChkStandard = True Then
cost = cost + 35
End If

If ChkStandard And Chkcalout = True Then
msg = "Standard Cost = " & card & vbCrLf & "Card = " & cost & vbCrLf & "Total Order =" & (15 + 35)
Buttons = vbInformation
Title = "Total Cost"
MsgBox msg, Buttons, Title
ElseIf Chkcalout = True Then
msg = "Callout Cost = " & card & vbCrLf & "Cost = " & cost & vbCrLf & "Total Order =" & (15 + ChkStandard)
Buttons = vbInformation
Title = "Total Cost"
MsgBox msg, Buttons, Title

ElseIf ChkStandard = True Then
msg = "Standard Cost = " & card & vbCrLf & "Card = " & cost & vbCrLf & "Total Order =" & (Chkcalout + 35)
Buttons = vbInformation
Title = "Total Cost"
MsgBox msg, Buttons, Title
End If

End Sub

liam1289
08-18-2010, 11:08 AM
Thanks a bunch..have you any good tutorials on loops being linked to speadsheet

Bob Phillips
08-18-2010, 01:31 PM
I don't know what that means.