Access 2010
Access 2003
Seminars
Tips & Tricks
Access Forum
Course Index Insider Circle
 
Tutorials   News   Tips   Forums   Help   Logon   Order  
 
 
 
Courses - Microsoft Access 311
Description: Advanced Access
Running Time: 86 minutes
Pre-Requisites: Access 310 very strongly recommended
Previous Lesson: Access 310
Next Lesson: Access 312
Main Topics: Profit, Loss, Unit Cost, Dynamic SQL, Format Function, SQL
Versions: This course is valid for Access 2000 through 2003. If you are using Access 2007 or 2010, you will still benefit from this course. You will find that the concepts are the same, but there are cosmetic differences between the versions.

    

Order before 5/20/2012 to get a FREE upgrade to our Access 2010 version!
Click here for details

 

Access 311 covers adding cost to our database so we can track net profit or loss for our sales. We'll also build a custom sales report and sales form for reporting. Finally, we'll create a form that has dynamically generated SQL to control what records and sorting are in the form.

First, I'd like to be able to figure out how much profit I'm making on each order by knowing the cost of my labors and materials. We'll start out by adding UnitCost info to our OrderDetailT and Order Subform. We'll add subtotals to the form as needed.

 

Next, we'll create a SalesReport query and report to show each order, what our cost is on that order, and what our net profit is.

 

Using our Sorting & Grouping levels and the Format() function, we'll create a custom format and breakdown for all of our sales by month.

 

We'll then create a simple form to set the limits (begin date and end date) for our sales report. Using the Forms ! FormName ! Field notation and the Between keyword to limit our sales query / report based on this information.

 

Next comes something that will add a whole new dimension to your form design... creating forms with a dynamic SQL statement controlling their records. In this case, we'll make our Order List form able to show quotes, invoices, paid invoices, unpaid invoices, and both quotes and invoices all by just selecting the option from a combo box. Our VBA code will construct an SQL statement which will update the records.

 

We'll also create a combo box to change which field our records are sorted by (company, name, amount due, order total, date, etc.) and a Sort A-to-Z or Z-to-A button to control ascending/descending sorts. This might sound easy, but we have to do it all using VBA code and events - take nothing for granted!

 

 


ACCESS 311 - Course Outline

0. Introduction - 2:42

1. Unit Cost on Orders - 13:16
Being able to calculate profit by knowing item costs
Adding UnitCost info to OrderDetailT
Creating an ExtendedCost field (UnitCost * Quantity)
Adding UnitCost and ExtCost to our OrderDetailF
Adding calculated totals to footer
Adding Cost fields to our Product Table
Get the product cost when a product is selected from ComboBox

2. Sales Report - 12:07
Creating a Sales Report with Cost & Profit
Add cost information to OrderListQ
Create the SalesReport Query and Report
Format() function to force numbers to show as currency

3. Sales Report & Form - 13:49
Adding totals to our Sales Report
Remember you can't put SUMs in your Page Footer
Create a Report Footer
Sort our Sales by Date - Sorting & Grouping Level
Group Header & Footer ON
Group On: Month
Format() Function: Format(OrderDate,"yyyy mmmm")
Criteria form to set begin date and end date for sales report
The Between keyword (remember me?)
[Date] is no good. Use Date()

4. Dynamic SQL Form 1 - 10:10
Clean up Customer List Form
Added Browse Customers and Add New Customer Buttons
DoCmd.GoToRecord acNewRec
Clean up Order List
Create an OrderList2Q so we can make more calculations
Add AmountDue information to OrderList form
Discuss what the Dynamic SQL Form is going to do

5. Dynamic SQL Form 2 - 14:44
Create a combo box with a list of options:
 - Show Invoices & Quotes
 - Show Quotes Only
 - Show Invoices Only
 - Show Paid Invoices Only
 - Show Unpaid Invoices Only
These are the options we want to see in our Order List Form
Set the default value for the combo box
Create an unbound text box to hold our SQL statement
Review of SQL Statements
SELECT Fields FROM Table WHERE Criteria ORDER BY Field
Create the BuildSQLStatement sub
Creating your own Private Sub
Set the form RecordSource equal to our SQL statement
Me.RecordSource = MySQL
Using VBA Code to build the SQL statement based on selection
Using a SELECT CASE statement instead of IF THEN statements
Creating another combo box for sorting:
 - Sort by Order Date
 - Sort by Company Name
 - Sort by Last Name
 - Sort by Order Total
 - Sort by Amount Due
Add another SELECT CASE to handle the ORDER BY clause

6. Dynamic SQL Form 3 - 17:07
Checking our Sort Combo Filter
Put a call to BuildSQLStatement in the SortCombo build event
Put a call to BuildSQLStatement in the form OnOpen event
DEFINITION - right click on a function or sub name to jump
Create our own Sort A to Z (ascending / descending) button
Capturing an image on the screen with Print-Screen
Drop that capture into Windows Paint
Cut out the buttons you want to "borrow"
Paste the buttons into your form.
Change the border style (raised, sunken)
Change the button names: SortAZ, SortZA
Make SortAZ visible, SortZA not visible
If the SortZA button is visible, add "DESC" to SQL Statement
Make OnClick events for each of these buttons
Change Enabled = YES for these buttons
"You can't hide a control that has the focus"
Shift the focus with DoCmd.GoToControl
Hide your SQL text box
Add buttons to browse orders, add new order
Change SortAZ and SortZA buttons to IMAGES not OLE objects

7. Review - 2:26


 

 

Student Interaction: Microsoft Access 311

Richard on 1/1/2008:  Access 311 covers adding COST to our product table and order details table so we can calculate job cost and net profit; dynamically generating SQL statements to control the records on a form; advanced sorting and grouping on reports; more with the Format() function; major overhaul to the OrderListF form.
Alan Hill on 1/11/2008: Some SQL's get pretty complicated. I found creating a query and switching to SQL mode, copying and pasting can be helpful. You did not cover that alternative. I thought the image AZ and ZA buttons was a neat trick. That was new to me.
Thanks

Richard Rost on 1/12/2008: I believe I covered this in Access 202. I showed you the button that switches between DESIGN mode and DATASHEET mode also can show you the SQL of a query. You're right though - I should have mentioned it again when we started covering dynamic SQL for forms.
 Harry on 4/11/2009: Is there an advantage to joining a first and last name using the record source of a text box on a form vs creating a custom field in the underlying query? I tend to prefer the latter as it seems a little quicker in rendering (esp for continuous forms) but I'm not sure.
 Harry on 4/11/2009: Whatis the purpose of a colon after each case statement? I've never seen that done nor used it myself. I can see it works, but what does it do?

 Harry on 4/11/2009: How can one open a form using dynamic sql (the dynamic part I can figure, the open part gives me fits) and avoid docmd.openform which seems to grab all records and then filter them?

As an aside, apart from increased network traffic in a multi user environment, the filters can be accidently messed with by the user causing no end of confusion. Any comments?

Richard Rost on 4/14/2009: Harry, both work just fine. I prefer the latter as well for continuous forms. For a single form, doing it on the form is OK, but the query is more efficient.
Richard Rost on 4/14/2009: Harry, the colon is a habit I picked up because (a) it's old school, and (b) it allows you to create a SINGLE-LINE case statement like this:

case "A": msgbox "do stuff"
case "B": msgbox "do other stuff"
case "C": msgbox "do yet more stuff"

And so on. You can't do this without the colon, so it just kinda stuck with me and I use it all the time.

Richard Rost on 4/14/2009: Harry, just don't specify a recordsource when you build the form. It will open blank. Then change the recordsource yourself in the OnOpen event to a single record with an SQL statement.
BRYAN binkerd on 6/5/2009: cool beans rick, you rock
Jane Hu on 7/31/2009: I see a VB code in the course:
Private Sub CompanyName_DblClick(...)
DoCmd OpenForm "CustomerF",,,"CustomerID=' & Cust....
Could you explain the use of ",,," in the code.
Also I can't see the whole VB code. Could you also explain please.
Thanks very much!

Richard Rost on 7/31/2009: Jane, there are extra parameters in there (additional options you can specify) that aren't important at this time. Don't worry about them. I'll cover them in future lessons.
David Leech on 9/28/2009: One of my favourite classes so far! I love that you decided to use the az za button for this. In my opinion the command buttons in access are pretty ugly,I anticipate using images alot more. much more fun :)
Really liked all these lessons. really cool stuff

Benjamin Chua on 10/28/2011: Class Access 311 Lesson 2 Time 11:52

In question of the Amount not showing as a Currency.

What I did, was I put a Round before the DSUM in the Query.

 

You may want to read these articles from the 599CD News:

 

 
Learn
 
Microsoft Access
Microsoft Excel
Microsoft Word
Microsoft Windows
Microsoft PowerPoint
Adobe Photoshop
Visual Basic
Active Server Pages
Online Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
WalkThru Tutorials
Free Upgrades
Insider Circle
Info
 
Latest News
New Releases
User Forums
Tips & Tricks
Search Our Site
Waiting List
Production Schedule
Help
 
Live Chat
Customer Support
Troubleshooting
FAQs
TechHelp
Consulting Services
About Us
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Order
 
Video Tutorials
Handbooks
MYOLP Memberships
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Live Chat
General Contact Info
Support Policy
Contact Form
Email Us
Mailing Address
Phone Number
Fax Number
Course Survey
Try Us
 
Free Lessons
Online Theater
Mailing List
Course Indexes:   Microsoft Access   Microsoft Excel   Microsoft Word   Microsoft PowerPoint   Visual Basic (VB)   Photoshop   Active Server Pages (ASP)  
Keyword Search Cloud:   What's This?   courses   microsoft access tutorials   vlookup   access   cartesian   excel   dlookup   vba   attendance   access 2007   sql   windows 7   combo box   pivot table   visual basic   test   iif   word   calendar   query   conditional formatting   pivot tables   photoshop   hlookup   access 101   excel 202   excel 2007   student attendance   update query   my account   word 2007   append query   quickbooks   queries   dsum   reports   powerpoint   if   microsoft access   dmax   mail merge   relationships   ms access   access 2010   vb   dcount   subforms   excel 2003   handbooks   html   599cd   combobox   if function   security   microsoft word   after update  
Copyright 2012 by 599CD.com, All Rights Reserved