![]() ![]() ![]() This can be done in the following manner: With Me.txtApplicationNo.Value = "".txtStudentID.Value = "".txtName.Value = "".txtAge.Value = "".txtAddress.Value = "".txtPhone.Value = "".txtCity.Value = "".txtCountry.Value = "".txtDOB.Value = "".txtZip.Value = "".txtNationality.Value = "".txtCourse.Value = "".txtCourseID.Value = "".txtenrollmentstart.Value = "".txtenrollmentend.Value = "".txtcourseduration.Value = "".txtDept.Value = "".cmbPaymentMode.Value = "".cmbPayment.Value = "".optFemale.Value = FalseEnd With In the clear button, you need to write the code to clear the existing values from the user form. We'll explain it thoroughly in the next section. If you're not sure what parts or any of the code means, don't worry. In the ensuing module, insert the following code: Private Sub CommandButton2_Click()‘declare the variables used throughout the codesDim sht As Worksheet, sht1 As Worksheet, lastrow As Long'Add validations to check if character values are being entered in numeric fields.If VBA.IsNumeric(txtApplicationNo.Value) = False ThenMsgBox "Only numeric values are accepted in the Application Number", vbCriticalExit SubEnd IfIf VBA.IsNumeric(txtStudentID.Value) = False ThenMsgBox "Only numeric values are accepted in the Student ID", vbCriticalExit SubEnd IfIf VBA.IsNumeric(txtAge.Value) = False ThenMsgBox "Only numeric values are accepted in Age", vbCriticalExit SubEnd IfIf VBA.IsNumeric(txtPhone.Value) = False ThenMsgBox "Only numeric values are accepted in Phone Number", vbCriticalExit SubEnd IfIf VBA.IsNumeric(Me.txtCourseID.Value) = False ThenMsgBox "Only numeric values are accepted in Course ID", vbCriticalExit SubEnd If'link the text box fields with the underlying sheets to create a rolling databaseSet sht = ThisWorkbook.Sheets("Student Database")'calculate last populated row in both sheetslastrow = sht.Range("a" & Rows.Count).End(xlUp).Row + 1'paste the values of each textbox into their respective sheet cellsWith sht.Range("a" & lastrow).Value = ("b" & lastrow).Value = ("c" & lastrow).Value = ("d" & lastrow).Value = ("e" & lastrow).Value = ("g" & lastrow).Value = ("h" & lastrow).Value = ("i" & lastrow).Value = ("j" & lastrow).Value = ("k" & lastrow).Value = ("l" & lastrow).Value = ("m" & lastrow).Value = ("n" & lastrow).Value = ("o" & lastrow).Value = ("p" & lastrow).Value = ("q" & lastrow).Value = ("r" & lastrow).Value = txtDept.ValueEnd Withsht.Activate'determine gender as per user's inputIf optMale.Value = True Then sht.Range("g" & lastrow).Value = "Male"If optFemale.Value = True Then sht.Range("g" & lastrow).Value = "Female"'Display a message box, in case the user selects the Yes radio buttonIf optYes.Value = True ThenMsgBox "Please select the payment details below"Else:Exit SubEnd IfEnd Sub ![]() Writing the Automated Form Code: Save Details ButtonÄouble-click on the Save Details button. ![]()
0 Comments
Leave a Reply. |