Unit 9 Spreadsheet development Create a user form
So far Unit introduction Learning aim A Features and uses Assignment 1 Learning aim B - Design a Spreadsheet Assignment 2
Learning aim C Develop and test a Spreadsheet Developing a spreadsheet solution: Use spreadsheet software tools and techniques, e.g.: Test and refine a spreadsheet
Learning aim C Develop and test a Spreadsheet Developing a spreadsheet solution: Use spreadsheet software tools and techniques, e.g.: Cell manipulation Cell formatting Data manipulation Formulae Functions Logical functions Data validation Relative and absolute cell referencing Boxes (lists, drop-down) Data entry forms
Learning aim C Develop and test a Spreadsheet Developing a spreadsheet solution: Use spreadsheet software tools and techniques, continued.: Lookup tables Nested IF functions Cell protection Types of charts and graphs Chart and graph formatting Worksheets Conditional formatting Named ranges Goal seek, what-if macros
Protect underlying data Guide user Files must be macro-enabled
Use partsinventorylist.xlsm Open the Visual Basic Editor (Alt + F11) Select View/ Project Explorer Select partsinventorylist.xlsm project Choose Insert/UserForm If the ToolBox doesn't appear, choose View Toolbox
Open the properties window ( F4) double-click on the Name -- UserForm1, at the top right of the window. Type a name frmpartlist double-click on the Caption property-- UserForm1 Type: Parts Inventory and press the Enter key The title bar will display the new caption.
Toolbox contains controls buttons, text boxes etc Click on text box button Add a text box, name it txtpart Labels give instructions or show user what a text box is for Add a label to the left of txtpart Change the caption to Part
Repeat the above steps to add: a textbox named txtloc, with a label Location a textbox named txtdate, with a label Date a textbox named txtqty, with a label Quantity To align: Click on the first textbox Hold the Ctrl key, and click on the remaining textboxes Choose Format Align Lefts Click on an empty part of the UserForm, to select the UserForm and to display the Toolbox.
Add buttons click at the bottom left, to add a standard sized CommandButton. With the new CommandButton selected, double-click on the Name property in the Properties window. Type: cmdadd Change the caption to Add this part Repeat the above steps to add a CommandButton named cmdclose, with a label Close
Add code to buttons Select the cmdadd button On the Menu bar, choose View Code. This creates a procedure, where you can add your code. Add code from cmdadd.txt Chose view Object to return to form
Add code to buttons Select the cmdclose button On the Menu bar, choose View Code. Add the following line of code: Unload Me To allow users to close the form by pressing the Esc key: Select the cmdclose button In the Properties window, change the Cancel property to True
To prevent users from closing the form by clicking the X button Right-click on an empty part of the UserForm Choose View Code From the Procedure dropdown, at the top right, choose QueryClose Add the following code, to the private-sub (UserForm_QueryClose) If CloseMode = vbformcontrolmenu Then Cancel Test the = True form: MsgBox "Please use the Close Form button!" On the Menu bar, choose Run Run Sub/UserForm. End If Fill in some details Click Add this Part Click close
Create a Button to open the UserForm Add a second sheet Name it Parts Data Entry Insert a shape Add the following text: Click here to add Part information Right-click on the rectangle border, and choose 'Assign Macro' Click the New button Where the cursor is flashing, type: frmpartlist.show
hide the sheet that contains the database. Select the PartsData sheet. On the Home tab choose Format Sheet Hide Click the Click here to add Part Information button, and enter your data into the database. Close and save the workbook https://www.contextures.com/xluserform01.html#setup