Cashflow Assignment Part2 Resit Stoke

advertisement
STAFFORDSHIRE UNIVERSITY
Faculty of Computing, Engineering and Technology
CE63025-3
Spreadsheet Automation with Visual Basic for Applications
2009/10
Referred Assignment: Monthly Expenditure Analysis
This referred assignment is equivalent to Part 2 of the assignment that you did in Semester 1.
The Task
Make a copy of the file Studentinfo on trentdev\SAVBA\Assignment files\Cashflow Part1.xlsm
and rename the copy as ab123456 Part2.xlsm where ab123456 is your username. This file contains
the “End_of_Month” macro written by David Noble for Part 1 of the assignment you did in Semester 1.
The file Cashflow2.xlsx in the SAVBA\Assignment files folder is the same as the file Cashflow.xlsx
that you used for Part 1 of this assignment except that it contains an “empty” worksheet for a new
month (in this case December), ie. no entries have yet been made for this month. Copy the
“December” worksheet into your file ab123456 Part2.xlsm so that it is the last sheet in your file.
The Task
In this referred assignment, you are required to create a user-friendly interface within ab123456
Part2.xlsm consisting of two Forms (an Initial Form and a Data Entry Form), full details of which are
given below).
The Initial Form
Automatically, on opening the workbook, the last sheet in the workbook (here, “December”) should be
selected and the Initial Form containing two option buttons (contained in a frame) and two command
buttons should be displayed. The two option buttons will allow the user to select one of
• Add a new item of income and expenditure
• Perform an end of month analysis (ie. Run the “End_of_Month” macro).
The two command buttons will have captions “OK” and “Exit”.
When the “Exit” button is clicked, the Initial form should cease to be displayed, leaving your file
ab123456 Part2.xlsm and all workbooks that have been created open. Any changes you may have
made to worksheets in ab123456 Part2.xlsm in order to create drop-down lists must be reversed/
removed.
Cashflow Assignment Part2 Resit Stoke
1
The “Perform an end of month analysis” option button on the Initial Form
If the “OK” command button on the Initial form is clicked when the “Perform an end of month analysis”
option button has been selected, your code should execute the “End_of_Month” macro to analyse the
data on the last (here “December”) worksheet in the file.
If the “End_of_Month” macro is executed, it will, on completion, prompt the user to see if the new
workbook that has been created should be saved or not. Whatever the user's response is, control
should then be returned to the Initial form and the “Perform an end of month analysis” option button
disabled.
After the “End_of_Month” macro has been executed, if further items of Income or Expenditure are
added, make sure that this new data is always added to the correct workbook and worksheet, ie.
here, to the last ("December") sheet in ab123456 Part2.xlsm and not to the new workbook that has
just been created. The same should be true if another "End_of_Month" analysis is subsequently
performed.
The “Add a new item of income and expenditure” option button on the Initial Form
If the “OK” command button is clicked when the “Add a new item of income and expenditure” option
button has been selected, code should be executed that displays the Data Entry Form. This single
form will contain all the Controls (detailed below) that are necessary to enter the data for a new item of
income or expenditure. However, when first displayed, all this form should allow the user to do is:
• select, using option buttons, whether to add an item to the Income part of the sheet or to the
Expenditure part, or
• close the Data Entry Form and return to the Initial Form (via a Command button).
Only once the user has clicked on either the Income or the Expenditure option buttons, should the
form then allow the appropriate data to be entered.
As you will have seen from the spreadsheet, the information to be entered differs depending on
whether an item is to be added to the Income section or to the Expenditure section. The following
table sets out the rules that should be enforced for each item of data along with the Control that
should be used to enable data entry.
Data
Date
Section
Both
Control
Textbox
Source
Payee
Income
Expenditure
Textbox
Textbox
Item
Category
Both
Expenditure
only
Textbox
Combobox
Cashflow Assignment Part2 Resit Stoke
Rules for data entry
A valid date in dd/mm/yy format is required
- initial value should be today's date.
The same textbox should be used for Source as for Payee but the
prompt/label alongside the textbox should change depending on
the option that has been chosen. No error checking required.
Initial value blank.
No error checking required. Initial value blank.
The dropdown list should contain the Category values your code
detects from the previous sheet (here, “November”), arranged in
alphabetical order.
The user should also be allowed to enter a Category that is not on
this list. If they do, the list should be expanded to include this new
item. Although the initial value on the form should be blank, a
blank entry is not allowed on the spreadsheet.
2
Method
Expenditure
only
Combobox
Amount
Both
Textbox
The dropdown list should contain the following five values:
cheque, credit, debit, d/d, s/o in that order.
These do not have to be detected and can be hard-coded.
The user should not be allowed to enter a Method that is not on
this list. Initial value blank.
Must be numerical. Initial value blank.
At any point during the entry of the data on the form, by clicking on an appropriately labeled button,
the user should be allowed to reset the form, ie. return it to the state it was in when first displayed.
Also, at any point during the entry of the data on the form, by clicking on a different appropriately
labeled button, the user should be allowed to initiate transfer of the data from the Data Entry form to
the spreadsheet. However, your code should not actually transfer the data until the error checks
listed in the table above have been satisfied. If any of the checks is not met, the user should be
warned (with a description of the error involved appearing in an appropriately positioned label on the
Data Entry form) and allowed to correct the entry before attempting to transfer the data to the
spreadsheet again.
Once all the data has passed the error checks, the data should be transferred to the spreadsheet and
the Data Entry form reset, ie. returned to the state it was in when first displayed, awaiting further
(possible) entries of Income or Expenditure.
When the data is transferred to the spreadsheet, each item must be moved to the appropriate cell in
the next empty row in the appropriate section (Income or Expenditure). Once entered, the data
should be sorted chronologically within each section. After adding an item to the Income section, your
code should also ensure that there are still two blank rows between the last Income item and the cell
containing the word "Expenditure".
In summary, you should have three command buttons on the Data Entry Form:
• one to reset any data that has been entered on the form,
• one to attempt to transfer the data to the worksheet (and succeed if the data validation checks are met),
• one to return the user to the Initial form.
As stated already, the last of these buttons is the only one that should be enabled when the Data
Entry form is first displayed. As soon as either the Income or Expenditure buttons is selected, it
should be disabled and should stay disabled until either the data has been reset or data has been
successfully transferred to the spreadsheet. You should thus not be able to return to the Initial form
until all data on the Data Entry form has been reset as a result of one of these two operations.
When control is returned to the Initial form, the “Perform an end of month analysis” option button
should be enabled provided there is at least one item of Income and at least one item of expenditure
in the last sheet in the file.
Your code must be written in such a way that it works for any similar (but different) set of data and for
any workbook where a new month sheet has already been added as the last sheet in the workbook
and where the entries for the Category drop-down list are detected from the penultimate worksheet.
Cashflow Assignment Part2 Resit Stoke
3
Help
There is no one way of completing this assignment successfully. That said, the Visual Basic Help on
the RowSource property, the AddItem method and the Style property may prove useful when you are
setting up your drop-down lists. Knowledge of the Enabled and Visible properties should also prove
useful.
For help on checking the validity of data, select Microsoft Visual Basic Documentation, Visual Basic
Language Reference, Indexes/Lists and look at the Data Types Keyword Summary.
Consult the Help (especially the last Paragraph) on “Show Method (Visual Basic for Applications)” and
the Hide method when customising your code to your UserForms.
Hand In
The ab123456 Part2.xlsm workbook, containing all your code and both UserForms necessary to
complete the task detailed above should be handed in on a disk/CD, clearly marked with your
username. Your disk should be accompanied by printouts of all the macros you have written (not the
“End_of_Month” macro). If your UserForms have been designed well and your macros have been
written well, no instructions should be necessary in order to run them successfully.
Late submission will not be accepted (except in the case of bona fide extenuating circumstances), in
accordance with the University’s published policy.
Resit Test
If you are required to resit the test for this Module, then you must make a second copy of your
ab123456 Part2.xlsm workbook and bring this with you when you attend the resit test for this module
which will be held on during the week beginning August 16 2010.
David Noble
Cashflow Assignment Part2 Resit Stoke
4
Download