Your task is to provide the code that will allow the user to enter to enter 5 numbers into text boxes on a form, click a button, and display those 5 numbers in a different set of boxes on the same form. see image.

You will be provided with a database (SortStudent.accdb)

There is a single form in the database called Sort Form

The text boxes and sort button have been provided.

The text boxes for the unsorted values are named txtUnsorted1, txtUnsorted2, , txtUnsorted5

The text boxes for the sorted values are named txtSorted1, txtSorted2, , txtSorted5

The clear button is named cmdClear, the sort button is named cmdSort.

Your code will be written for the click event of the cmdSort button.

Using the Access Code Window

When you open the database, it will open to an empty window. On the left, under All Access Objects, double click on the Sort Form see image.

The form will open in form view, which means it's live and ready to run.

To put code in, the form needs to be in design view.

Right click on the Sort Form tab and choose Design view or Below the File Tab at the top left, click on View Button and Choose Design View see image.

The form will open in Design View see image.

At the top, the Form Design Tools Tab will show and the Design Tab will be active. Click on the Design Tab to activate if needed.

To Open the Code Window, click on the view Code button see image.

The code page will open in a separate window. see image.

Variables have been provide for capturing the user input and holding a value temporarily.

The functionality for the Clear button has been provided.

Your code should go into the area for the click event for the Sort button.

Using the algorithm and code constructs discussed in the lecture, build the code that sorts the values and displays the result on the form

FOR Construct
FOR count = start To end (start and end are numbers)
1 or more instructions
NEXT count

IF Construct(s)
IF logical test THEN instruction

IF logical test THEN
multiple instructions
END IF

Pseudo code

Get values entered by user

Check 1st 2 values
If Value 1 > Value 2
Temp = Value1
Value 1= Value 2
Value 2 = Temp

Repeat for each set of values in the list

Repeat sufficiently to sort all values

Display results on the form

Running the Program

Once you have put your code in, save it by clicking on the save button on the upper left. see image.

Close the code window.

Switch the form from design view to form view

Right click on the Sort Form tab and choose Design view or Below the File Tab at the top left, click on View Button and choose Design View see image.

The form opens in form view. Enter some values and click on Sort Values to run your code. see image.

Hopefully everything works and you're done. Test a few sets to make sure.

If there's an error in your logic, switch back to design view, update the code and try again until you get it right.

If there's a syntax error, the program will suspend execution, the code window will open and the error will be highlighted on your screen. Or you may get a run time error message, click on debug and the code window will open.

Make note of the error click OK. see image.

The error will be highlighted. NoteThe highlight does not necessarily mean that there is a problem with this line of code, it just means the program stopped here. In this example, there's no end to the if statement so the program halted on the last line that it ran.

Private Sub cmdSort_Click()
If a Then

End Sub

Take note of the location. Because the program is suspended, you have to reset the program before you can fix it. Once you reset the program, the highlighting goes away.

Click on the Reset button on the tool bar to stop execution. If you try to make changes before stopping the program, you may get the stop debugger message. Click OK to reset the program. see image.

Fix your code, save it, close the code window and try running it again.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.