Advertisement
mir456789

Code

Apr 19th, 2024
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3.  
  4. Private Sub cmb10_Click()
  5.     If MultiPage1.Value < MultiPage1.Pages.Count - 1 Then
  6.         MultiPage1.Value = MultiPage1.Value + 1
  7.     End If
  8. End Sub
  9.  
  10. Private Sub cmb11_Click()
  11.     If MultiPage1.Value > 0 Then
  12.         MultiPage1.Value = MultiPage1.Value - 1
  13.     End If
  14. End Sub
  15.  
  16. Private Sub cmb12_Click()
  17.     Me.Hide
  18. End Sub
  19.  
  20.  
  21.  
  22. Private Sub cmb4_Click()
  23.     If MultiPage1.Value < MultiPage1.Pages.Count - 1 Then
  24.         MultiPage1.Value = MultiPage1.Value + 1
  25.     End If
  26. End Sub
  27.  
  28. Private Sub cmb5_Click()
  29.     If MultiPage1.Value > 0 Then
  30.         MultiPage1.Value = MultiPage1.Value - 1
  31.     End If
  32. End Sub
  33.  
  34. Private Sub cmb6_Click()
  35.     Me.Hide
  36. End Sub
  37.  
  38. Private Sub cmb7_Click()
  39.     If MultiPage1.Value < MultiPage1.Pages.Count - 1 Then
  40.         MultiPage1.Value = MultiPage1.Value + 1
  41.     End If
  42. End Sub
  43.  
  44. Private Sub cmb8_Click()
  45.     If MultiPage1.Value > 0 Then
  46.         MultiPage1.Value = MultiPage1.Value - 1
  47.     End If
  48. End Sub
  49.  
  50. Private Sub cmb9_Click()
  51.     Me.Hide
  52. End Sub
  53.  
  54. Private Sub cmbPlan_Change()
  55.   With cmbPlan
  56.         .AddItem "Essential"
  57.         .AddItem "Ward"
  58.         .AddItem "Semi-Private"
  59.         .AddItem "Private"
  60.     End With
  61.    
  62.    
  63.  Dim Ans As String
  64.  Ans = cmbPlan.Value
  65.  
  66.        
  67. End Sub
  68.  
  69.  
  70.  
  71. Private Sub CommandButton1_Click()
  72.     Me.Hide
  73. End Sub
  74.  
  75. Private Sub Add_SatusItems()
  76.     With ListBox_SmokingStatus
  77.         .AddItem "Non-Smoker"
  78.         .AddItem "Occasional"
  79.         .AddItem "Regular"
  80.     End With
  81.  
  82.     With ListBox_DrinkingStatus
  83.         .AddItem "Non-Drinker"
  84.         .AddItem "Occasional"
  85.         .AddItem "Regular"
  86.     End With
  87.  
  88.     With ListBox_LifestyleStatus
  89.         .AddItem "Non-Active"
  90.         .AddItem "Occasional"
  91.         .AddItem "Regular"
  92.     End With
  93. End Sub
  94.  
  95.  
  96. Private Sub cmb13_Click()
  97.     On Error GoTo ErrorHandler
  98.  
  99. Dim Firstname As String  ' Updated variable name
  100. Dim address As String
  101. Dim DOB As Date
  102. Dim Planstart As Date
  103. Dim Age As Integer
  104. Dim Number As String
  105. Dim emnum As String
  106. Dim Occupation As String
  107. Dim HKID As String
  108. Dim Gender As String
  109. Dim Smoke As Boolean
  110. Dim Alcohol As Boolean
  111. Dim ChosenPlan As Date
  112. Dim Health As String
  113. Dim Lifestyle As String
  114. Dim paymentFreq As Integer
  115. Dim Premium As String
  116. Dim Dec As Boolean
  117. Dim Con As Boolean
  118.  
  119.  
  120. Call txtFirstname_Change
  121. Call txtDOB_Change
  122. Call txtAddress_Change
  123. Call txtContactNo_Change
  124. Call txtEmergencyNo_Change
  125. Call txtHKID_Change
  126. Call txtOccupation_Change
  127. Call cmbPlan_Change
  128.  
  129.  
  130. ' Rest of the code remains the same
  131.    If Me.optbMale.Value = True Then
  132.         Call optbMale_Click
  133.     ElseIf Me.optbFemale.Value = True Then
  134.         Call optbFemale_Click
  135.     End If
  136.    
  137.     If Me.optbAllergiesYes.Value = True Then
  138.         Call optbAllergiesYes_Click
  139.     ElseIf Me.optbAllergiesNo.Value = True Then
  140.         Call optaAllergiesNo_Click
  141.     End If
  142.    
  143.  If optbMedConYes.Value = True Then
  144.         Call optbMedConYes_Click
  145.     ElseIf Me.optbMedConNo.Value = True Then
  146.         Call optbMedConYes_Click
  147.     End If
  148.  If optbHealthConHyper.Value = True Then
  149.     Call optbHealthConHyper_Click
  150.     ElseIf optbHealthConDiabates.Value = True Then
  151.         Call optbHealthConDiabates_Click
  152.     ElseIf optbHealthConAsthma.Value = True Then
  153.         Call optbHealthConAsthma_Click
  154.     Else
  155.          Call optbHealthConCancer_Click
  156.          
  157.     If optbAnyYes.Value = True Then
  158.         Call optbAnyYes_Click
  159.     Else
  160.         optbAnyNo_Click
  161.    
  162.        
  163.          
  164. Call ListBox_SmokingStatus_Click
  165. Call ListBox_DrinkingStatus_Click
  166. Call ListBox_LifestyleStatus_Click
  167. Call Premium_Click
  168. Call spinbYear_Change
  169. Call txtYear_Change
  170. Call btnDecrease_Click
  171. Call txtPayFreq_Change
  172. Call spinbPay_Change
  173. Call txtPlanDate_Change
  174. Call optbDeclaration_Click
  175. Call optbConsent_Click
  176.  
  177.     Alcohol = (Me.chkAlcohol.Value = True)
  178.     Dec = (Me.chkDec.Value = True)
  179.     Con = (Me.chkCon.Value = True)
  180.  
  181.     Dim Record As Worksheet
  182.     Set Record = ThisWorkbook.Sheets("Enrollment")
  183.  
  184.     Dim nextRow As Long
  185.     nextRow = Record.Range("A" & Record.Rows.Count).End(xlUp).Row + 1
  186.  
  187.     Record.Range("A" & nextRow).Value = Fname
  188.     Record.Range("B" & nextRow).Value = Age
  189.     Record.Range("C" & nextRow).Value = Gender
  190.     Record.Range("D" & nextRow).Value = Occupation
  191.     Record.Range("E" & nextRow).Value = HKID
  192.     Record.Range("F" & nextRow).Value = Number
  193.     Record.Range("G" & nextRow).Value = Smoke
  194.     Record.Range("H" & nextRow).Value = Alcohol
  195.     Record.Range("I" & nextRow).Value = Health
  196.     Record.Range("J" & nextRow).Value = Lifestyle
  197.     Record.Range("K" & nextRow).Value = ChosenPlan
  198.     Record.Range("L" & nextRow).Value = Premium
  199.     Record.Range("M" & nextRow).Value = paymentFreq
  200.  
  201.     MsgBox "Enrollment details saved successfully.", vbInformation
  202.     Exit Sub
  203.  
  204. ErrorHandler:
  205.     MsgBox "An error occurred while saving the enrollment details.", vbCritical
  206. End Sub
  207.  
  208.  
  209.  
  210.  
  211. Private Sub ListBox_DrinkingStatus_Click()
  212.     Dim selectedChoice As String ' Variable to store the user's choice
  213.    
  214.     With ListBox_DrinkingStatus
  215.         .AddItem "Non-Drinker"
  216.         .AddItem "Occasional"
  217.         .AddItem "Regular"
  218.     End With
  219.    
  220.     If ListBox_DrinkingStatus.ListIndex <> -1 Then ' Check if an item is selected
  221.        selectedChoice = ListBox_DrinkingStatus.Value ' Store the selected choice
  222.    Else
  223.         MsgBox "Please select a drinking status." ' Display an error message if no item is selected
  224.    End If
  225.    
  226.     ' Now you can use the selectedChoice variable for further processing or storing the value.
  227.    ' Example: You can assign it to a different variable or use it in your code as needed.
  228.    
  229.     ' For example, if you have another variable called drinkChoice, you can assign the selectedChoice value to it:
  230.    ' drinkChoice = selectedChoice
  231. End Sub
  232. Private Sub ListBox_LifestyleStatus_Click()
  233.     Dim selectedChoice As String ' Variable to store the user's choice
  234.    
  235.     With ListBox_LifestyleStatus
  236.         .AddItem "Non-Active"
  237.         .AddItem "Occasional"
  238.         .AddItem "Regular"
  239.     End With
  240.    
  241.     If ListBox_LifestyleStatus.ListIndex <> -1 Then ' Check if an item is selected
  242.        selectedChoice = ListBox_LifestyleStatus.List(ListBox_LifestyleStatus.ListIndex) ' Store the selected choice
  243.    Else
  244.         MsgBox "Please select a lifestyle status." ' Display an error message if no item is selected
  245.    End If
  246.    
  247.     ' Now you can use the selectedChoice variable for further processing or storing the value.
  248.    ' Example: You can assign it to a different variable or use it in your code as needed.
  249.    
  250.     ' For example, if you have another variable called lifestyleChoice, you can assign the selectedChoice value to it:
  251.    ' lifestyleChoice = selectedChoice
  252. End Sub
  253.  
  254. Private Sub ListBox_SmokingStatus_Click()
  255.     Dim selectedChoice As String ' Variable to store the user's choice
  256.    
  257.     With ListBox_SmokingStatus
  258.         .AddItem "Non-Smoker"
  259.         .AddItem "Occasional"
  260.         .AddItem "Regular"
  261.     End With
  262.    
  263.     If ListBox_SmokingStatus.ListIndex <> -1 Then ' Check if an item is selected
  264.        selectedChoice = ListBox_SmokingStatus.List(ListBox_SmokingStatus.ListIndex) ' Store the selected choice
  265.    Else
  266.         MsgBox "Please select a smoking status." ' Display an error message if no item is selected
  267.    End If
  268.    
  269.     ' Now you can use the selectedChoice variable for further processing or storing the value.
  270.    ' Example: You can assign it to a different variable or use it in your code as needed.
  271.    
  272.     ' For example, if you have another variable called userChoice, you can assign the selectedChoice value to it:
  273.    ' userChoice = selectedChoice
  274. End Sub
  275.  
  276. Private Sub MultiPage1_Change()
  277.  
  278. End Sub
  279.  
  280. Private Sub optbAllergiesNo_Click()
  281. Dim Allergy As String
  282. Allergy = Me.optbAllergiesNo.Value
  283. End Sub
  284.  
  285. Private Sub optbAllergiesYes_Click()
  286. Dim Allergy As String
  287. Allegy = Me.optbAllergiesYes.Value
  288.  
  289. End Sub
  290.  
  291. Private Sub optbAnyNo_Click()
  292. Dim med As String
  293. med = optbAnyNo.Value
  294.  
  295. End Sub
  296.  
  297. Private Sub optbAnyYes_Click()
  298. Dim med As String
  299. med = optbAnyYes.Value
  300.  
  301. End Sub
  302.  
  303.  
  304. Private Sub optbDeclaration_Click()
  305.     ' Assuming you have a CheckBox named "chkAgreeDeclaration"
  306.    If Not optbDeclaration.Value Then
  307.         MsgBox "Please check the declaration box to proceed.", vbExclamation
  308.         optbDeclaration.Value = False ' Uncheck the option button
  309.    End If
  310.  
  311. End Sub
  312.  
  313. Private Sub optbConsent_Click()
  314.  
  315.     ' Assuming you have a CheckBox named "optbConsent"
  316.    If Not optbConsent.Value Then
  317.         MsgBox "Please check the consent box to proceed.", vbExclamation
  318.         optbConsent.Value = False ' Uncheck the option button
  319.    End If
  320.  
  321.  
  322. End Sub
  323.  
  324. Private Sub optbFemale_Click()
  325. Dim Gender As String
  326. Gender = Me.optbFemale.Value
  327. Gender = "Female"
  328.  
  329. End Sub
  330.  
  331. Private Sub optbHealthConAsthma_Click()
  332. Dim Asthama As String
  333. Asthama = optbHealthConAsthama.Value
  334. End Sub
  335.  
  336. Private Sub optbHealthConCancer_Click()
  337. Dim None As String
  338.     None = optbHealthConCancer.Value
  339.    
  340.  
  341. End Sub
  342.  
  343. Private Sub optbHealthConDiabates_Click()
  344. Dim Diabetes As String
  345. Diabetes = optbHealthConDiabates.Value
  346.  
  347.  
  348. End Sub
  349.  
  350. Private Sub optbHealthConHyper_Click()
  351.     Dim Hyper As String
  352.     Hyper = optbHealthConHyper.Value
  353.    
  354. End Sub
  355.  
  356. Private Sub optbMale_Click()
  357. Dim Gender As String
  358. Gender = Me.optbMale.Value
  359. Gender = "Male"
  360.  
  361.  
  362. End Sub
  363.  
  364. Private Sub optbMedConYes_Click()
  365.     Dim MedCon As String
  366.     MedCon = "Yes"
  367. End Sub
  368.  
  369. Private Sub optbMedConNo_Click()
  370.     Dim MedCon As String
  371.     MedCon = "No"
  372. End Sub
  373.  
  374. Private Sub cmbPremium_Change()
  375.     Dim selectedChoice As String ' Variable to store the user's choice
  376.    
  377.     With cmbPremium
  378.         .AddItem "Base premium"
  379.     End With
  380.    
  381.     If cmbPremium.ListIndex <> -1 Then ' Check if an item is selected
  382.        selectedChoice = cmbPremium.Value ' Store the selected choice
  383.    Else
  384.         MsgBox "Please select a premium option." ' Display an error message if no item is selected
  385.    End If
  386.    
  387.     ' Now you can use the selectedChoice variable for further processing or storing the value.
  388.    ' Example: You can assign it to a different variable or use it in your code as needed.
  389.    
  390.     ' For example, if you have another variable called premiumChoice, you can assign the selectedChoice value to it:
  391.    ' premiumChoice = selectedChoice
  392. End Sub
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402. Private Sub spinbYear_Change()
  403.     Dim currentNumber As Double
  404.     currentNumber = CDbl(txtYear.Value)
  405.  
  406.     currentNumber = currentNumber + 0.5
  407.     txtNumber.Value = currentNumber
  408.    
  409. End Sub
  410. Private Sub btnDecrease_Click()
  411.     Dim currentValue As Double
  412.     currentValue = CDbl(txtYear.Value)
  413.     currentValue = currentValue - 0.5
  414.     txtYear.Value = currentValue
  415. End Sub
  416.  
  417. Private Sub txtAddress_Change()
  418. Dim Addres As String
  419. Addres = Me.txtAddress.Value
  420. End Sub
  421.  
  422. Private Sub txtContactNo_Change()
  423. Dim num As String
  424. num = Me.txtContactNo.Value
  425.  
  426. End Sub
  427.  
  428. Private Sub txtDOB_Change()
  429.  
  430.     Dim DOB As Date
  431.     Dim validDate As Boolean
  432.    
  433.     validDate = IsDate(Me.txtDOB.Value)
  434.    
  435.     If validDate Then
  436.         DOB = CDate(Me.txtDOB.Value)
  437.         ' Date is valid, you can use the DOB variable for further processing or storing the value.
  438.        ' Example: You can assign it to a different variable or use it in your code as needed.
  439.        ' For example, if you have another variable called dateOfBirth, you can assign the DOB value to it:
  440.        ' dateOfBirth = DOB
  441.    Else
  442.         MsgBox "Invalid date. Please enter a valid date."
  443.         Me.txtDOB.Value = ""
  444.         Me.txtDOB.SetFocus
  445.     End If
  446. End Sub
  447.  
  448.  
  449. Private Sub txtEmergencyNo_Change()
  450. Dim emnum As String
  451. emnum = Me.txtEmergencyNo.Value
  452. End Sub
  453.  
  454. Private Sub txtFirstname_Change()
  455. Dim Name As String
  456. Name = Me.txtFirstname.Value
  457.  
  458. End Sub
  459.  
  460. Private Sub txtHKID_Change()
  461. Dim ID As String
  462. ID = Me.txtHKID.Value
  463.  
  464. End Sub
  465.  
  466. Private Sub txtOccupation_Change()
  467. Dim work As String
  468. work = Me.txtOccupation.Value
  469.  
  470. End Sub
  471.  
  472. Private Sub txtPayFreq_Change()
  473.     Dim currentValue As Integer
  474.     currentValue = CInt(txtPayFreq.Value) ' Assuming you have a TextBox named "txtPayFreq"
  475.  
  476.     ' Store the currentValue in a variable or perform any other desired actions
  477.    ' For example, you can store it in a global variable or process it further
  478.  
  479. End Sub
  480.  
  481. Private Sub spinbPay_Change()
  482.     Dim currentValue As Integer
  483.     currentValue = CInt(txtPayFreq.Value) ' Assuming you have a TextBox named "txtPayFreq"
  484.  
  485.     ' Determine which spin button was clicked
  486.    If spinbPay.Value > currentValue Then
  487.         ' Increase button was clicked
  488.        currentValue = currentValue + 1
  489.     ElseIf spinbPay.Value < currentValue Then
  490.         ' Decrease button was clicked
  491.        currentValue = currentValue - 1
  492.     End If
  493.  
  494.     ' Update the TextBox with the new value
  495.    txtPayFreq.Value = currentValue
  496. End Sub
  497.  
  498. Private Sub txtPlanDate_Change()
  499.     Dim enteredDate As Date
  500.     Dim isValidDate As Boolean
  501.  
  502.     ' Attempt to parse the entered text as a date
  503.    On Error Resume Next
  504.     enteredDate = CDate(txtPlanDate.Value)
  505.     On Error GoTo 0
  506.  
  507.     ' Check if the entered date is valid
  508.    isValidDate = (Err.Number = 0)
  509.  
  510.     If isValidDate Then
  511.         ' Date is valid, perform desired actions or store the date
  512.        ' You can replace the message box with your desired logic
  513.        MsgBox "Entered date: " & enteredDate
  514.     Else
  515.         ' Invalid date entered, display message box and prompt for re-entry
  516.        MsgBox "Invalid date entered. Please enter a valid date.", vbExclamation
  517.         txtPlanDate.Value = ""
  518.         txtPlanDate.SetFocus
  519.     End If
  520. End Sub
  521.  
  522. Private Sub txtYear_Change()
  523. Dim inputValue As Double
  524. Dim storedValue As Double
  525.     inputValue = CDbl(txtYear.Value)
  526.     storedValue = inputValue
  527. End Sub
  528.  
  529. Private Sub UserForm_Activate()
  530.  
  531. Call Add_SatusItems
  532. Call ListBox_SmokingStatus_Click
  533. Call ListBox_DrinkingStatus_Click
  534. Call ListBox_LifestyleStatus_Click
  535. Call cmbPlan_Change
  536. Call cmbPremium_Change
  537.  
  538.  
  539.  
  540. End Sub
  541.  
  542.  
  543.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement