[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 735
  • Last Modified:

Access roster view

Hi,
I have a database for all staff job allocations for my work using MS Access 2007/2010 asthe frontend. There is a record created each date a member of staff is placed on a job. It would be really useful to be able to display the dates for an entire month showing which jobs somebody is assigned to. At the moment i have some VBA code which runs through the entire month checking each day to see if there is a job assigned and creating a blank, dummy record if it isnt. This is very slow and cumbersome and doesnt allow quick updating of the records. Is there a better way of doing this?

Many thanks,
Chris
0
chrisryan43
Asked:
chrisryan43
2 Solutions
 
Andrew_WebsterCommented:
Yes there is.

Create a dates table.  The quick way to do this is to use Excel: enter the first couple of dates then select them and drag down to create a whole list of dates.  Copy this into a table in Access.

Now create a query - the key is the OUTER JOIN - that shows what you want.

Something like:

SELECT roster.staffmember, dates.thedate FROM roster LEFT OUTER JOIN dates ON roster.thedate = dates.thedate.

This will show "staffmember" that has a "thedate" matched in "dates" and every "thedate" from dates regardless of whether it's matched in "roster".  Does that make sense?

(I've used "thedate" as "date" is a reserved word, and it's good practice to avoid naming table fields with reserved words.)
0
 
Helen FeddemaCommented:
You can use the DateAdd function in Access to create a table filled with incrementing dates.  Here is some code that fills a table with incrementing month-year values; you can modify it to create dates, just incrementing by day instead of month.
'Clear MonthYear table
   strMonthYearTable = "zstblAllMonthYears"
   strSQL = "DELETE * FROM " & strMonthYearTable & ";"
   DoCmd.SetWarnings False
   DoCmd.RunSQL strSQL
   
   strCurrentYear = Year(Date)
   strCurrentMonth = Month(Date)
   
   dteStart = DateAdd("m", -13, Date)
   dteEnd = DateAdd("m", 12, Date)
   Debug.Print "Date range: " & CStr(dteStart) & " to " & CStr(dteEnd)
   
   Set dbs = CurrentDb
   Set rst = dbs.OpenRecordset(strMonthYearTable)
   
   For intMonth = 1 To 24
      dteDynamicMonth = DateAdd("m", intMonth, dteStart)
      strMonthYear = Year(dteDynamicMonth) & "-" & Format(Month(dteDynamicMonth), "00")
      'Add a record to month-year table
      rst.AddNew
      rst![MonthYear] = strMonthYear
      rst.Update
   Next intMonth
      
   rst.Close

Open in new window

0
 
chrisryan43Author Commented:
Amazing! Thankyou so so much!

All working beautifully now
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now