Timesheet PayPeriod Design

B

Billiam

I am wondering if anyone could advise on a good timesheet design.

I would like my timesheet form to display the payperiod from a combobox.

I think I would just make a reference/lookup table with all the possible
values...Could this be done from a make table query which would automatically
make the table based on the year? and is there an example of this, or would
someone be able to help me as i have never done this before?

Thank you for any help!

Billiam
 
A

Arvin Meyer [MVP]

Billiam said:
I am wondering if anyone could advise on a good timesheet design.

I would like my timesheet form to display the payperiod from a combobox.

I think I would just make a reference/lookup table with all the possible
values...Could this be done from a make table query which would
automatically
make the table based on the year? and is there an example of this, or
would
someone be able to help me as i have never done this before?

Here's some code that will help:

Public Function BuildCalendar(strTablename As String, _
dtmStart As Date, _
dtmEnd As Date, _
ParamArray varDays() As Variant)
'********************************************************************
' Name: BuildCalendar
' Purpose: Create a calendar table
'
' Inputs: strTableName As String
' dtIn As Date
' dtmEnd As Date
' ParamArray varDays() As Variant
' Author: Arvin Meyer
' Date: January 09, 2000
' Comment: Days of week to be included in calendar
' as value list: 2,3,4,5,6 for Mon-Fri
' Use 0 to include all days of week
'
'********************************************************************

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim strSQL As String
Dim dtmDate As Date
Dim varDay As Variant
Dim lngDayNum As Long

Set db = CurrentDb

If CheckTable(strTablename) = True Then
If MsgBox(" That table exists replace it? " & _
strTablename & "?", vbYesNo + vbQuestion, _
"Delete Table?") = vbYes Then
strSQL = "DROP TABLE " & strTablename
db.Execute strSQL
Else
Exit Function
End If
End If

On Error GoTo Err_BuildCalendar

' create new table
strSQL = "CREATE TABLE " & strTablename & _
"(DateField DATETIME, " & _
"CONSTRAINT PrimaryKey PRIMARY KEY (DateField))"
db.Execute strSQL

' refresh database window
Application.RefreshDatabaseWindow

If varDays(0) = 0 Then
' fill table with all dates
For dtmDate = dtmStart To dtmEnd
lngDayNum = lngDayNum + 1
strSQL = "INSERT INTO " & strTablename & "(DateField) " & _
"VALUES(#" & Format(dtmDate, "mm/dd/yyyy") & "#)"

db.Execute strSQL
Next dtmDate
Else
' fill table with dates of selected days of week only
For dtmDate = dtmStart To dtmEnd
For Each varDay In varDays()
If Weekday(dtmDate) = varDay Then
lngDayNum = lngDayNum + 1
strSQL = "INSERT INTO " & strTablename & "(DateField) "
& _
"VALUES(#" & Format(dtmDate, "mm/dd/yyyy") &
"#)"
db.Execute strSQL
End If
Next varDay
Next dtmDate
End If

Exit_BuildCalendar:
Set db = Nothing
Set tdf = Nothing
Exit Function

Err_BuildCalendar:
Resume Exit_BuildCalendar

End Function
 
B

Billiam

Thank you very much, Arvin! I will play with this to see if i can get it to
work. have a great weekend!
best regards,
Billiam
 
B

Billiam

Hi Arvin,

Do I create a module, then click on compile 9under debug) to get this to
work...it is saying Compile error:Sub or function not defined and CheckTable
is highlighted.

Sorry, I am new to this and do not know what to do really...

Billiam
 
D

Douglas J. Steele

It's not your fault: Arvin forgot to give you the code for CheckTable.

It could be something like:

Function CheckTable(TableName) As Boolean
' Returns True if TableName exists, False otherwise

CheckTable = Not IsNull(DLookup("Name", "MSysObjects", _
"Type = 1 And Name = '" & TableName & "'"))

End Function

Just add that to the end of the module you created.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)
 
B

Billiam

Thank you Douglas...it is very kind of you to help! I will try this tonight.
Best Regards,
Billiam
 
B

Billiam

Hi Douglas,

I inserted the function you supplied at the end of the module, however, it
is still highlighting this line from Arvin's code as a syntax error:

If CheckTable(strTablename) = True Then

This is how inexperienced i am at this, Doug, but, when i see the
underscore...I am assuming that i am supposed to bring the following line to
that point and replace the underscore...is this correct?

Billiam
 
D

Douglas J. Steele

While you can do what you're describing with the underscore, it's not
necessary. You could have simply copied-and-pasted the code as-is into your
module.

Just to be clear: you put that in the same module as the rest of Arvin's
code, right? What have you named the module?
 
B

Billiam

Thank you, Ken. i will try that today.
As always, your help is GREATLY appreciated!
Billiam

KenSheridan via AccessMonster.com said:
Billiam:

Or it can be done without the need for the CheckTable function, as in my
original code, from which Arvin's is largely taken, by amending it as follows:


' does table exist? If so get user confirmation to delete it
On Error Resume Next
Set tdf = dbs.TableDefs(strTablename)
If Err = 0 Then
If MsgBox("Replace existing table: " & _
strtable & "?", vbYesNo + vbQuestion, _
"Delete Table?") = vbYes Then
strSQL = "DROP TABLE " & strTablename
dbs.Execute strSQL
Else
Exit Function
End If
End If
On Error GoTo 0

Ken Sheridan
Stafford, England
Hi Douglas,

I inserted the function you supplied at the end of the module, however, it
is still highlighting this line from Arvin's code as a syntax error:

If CheckTable(strTablename) = True Then

This is how inexperienced i am at this, Doug, but, when i see the
underscore...I am assuming that i am supposed to bring the following line to
that point and replace the underscore...is this correct?

Billiam
It's not your fault: Arvin forgot to give you the code for CheckTable.
[quoted text clipped - 122 lines]
End Function
 
J

James A. Fortune

KenSheridan said:
Billiam:

Or it can be done without the need for the CheckTable function, as in my
original code, from which Arvin's is largely taken, by amending it as follows:


' does table exist? If so get user confirmation to delete it
On Error Resume Next
Set tdf = dbs.TableDefs(strTablename)
If Err = 0 Then
If MsgBox("Replace existing table: " & _
strtable & "?", vbYesNo + vbQuestion, _
"Delete Table?") = vbYes Then
strSQL = "DROP TABLE " & strTablename
dbs.Execute strSQL
Else
Exit Function
End If
End If
On Error GoTo 0

Ken Sheridan
Stafford, England

I like the user confirmation for the table deletion and using DROP TABLE
is nice, but I like to avoid raising errors whenever possible. I also
don't like relying on the relatively undocumented and unsupported
MSysObjects table. Therefore, I submit the following additional
alternative method for seeing if a table exists. It doesn't prevent
another user from dropping the table immediately before you try dropping
it, but that situation is better suited for error trapping than for
detecting if a table exists IMO. I suspect that the time it takes to
search for the table name in TableDefs and raise an error when the table
name is not there is longer than the time it takes just to search
through all the table names in the TableDefs Collection.

---'begin module code
Public Function DoesTableExist(strTableName As String) As Boolean
Dim MyDB As DAO.Database
Dim tdf As TableDef

DoesTableExist = False
Set MyDB = CurrentDb()
For Each tdf In MyDB.TableDefs
If tdf.Name = strTableName Then
Set MyDB = Nothing
DoesTableExist = True
Exit Function
End If
Next tdf
Set MyDB = Nothing
End Function
---'end module code

James A. Fortune
(e-mail address removed)
 
J

James A. Fortune

KenSheridan said:
Always good to have the benefit of your views, James.

I respect and value your contributions also.
I agree absolutely about the inadvisability of using the system tables; BTW
isn't 'relatively undocumented' rather like being 'slightly pregnant'?

:)

Using the system tables is probably not as bad as I made it sound.
There was an unofficial leak from MichKa that no existing fields in the
MSysObjects table will be deleted or changed in the future. In theory,
since the MSysObjects table seems to be used by Access internally at
least to display the contents of the various collections for each tab,
the technique differs little in concept from using the API functions
used by Windows or borrowing functionality from the .NET Framework.
However, Microsoft makes less guarantees about the future structure of
the MSys tables than it has, so far, about the backward compatibility of
standard collections. Even the use of API functions requires the
developer to be on guard against certain functions changing signatures
or becoming obsolete and even removed. Without native compilation,
using existing or custom .NET Framework DLL's depends on certain
assumptions about the existence of the .NET Framework "Runtime." So
even though the "borrowing" techniques are not bad, per se, sometimes
better choices are available. For example, if all the computers at a
company have the latest .NET Framework on them, then moving from the API
functions to managed functions would remove the dependency on the API
functions remaining the same at the expense of keeping track of a DLL
file. Sometimes the better choices for me aren't all that much better
than the alternatives.

James A. Fortune
(e-mail address removed)

Made up words:

calliarchy - 1) rule by the beautiful 2) rule by the power of beauty

callifdom - a kingdom governed by a calliarchy

I chose callifdom to be similar in construction to a fiefdom so as not
to be confused with a caliphate. Perhaps phobiarchy could use phobifdom
or phobiphate?
 
J

James A. Fortune

KenSheridan said:
There are some real (classical) Greek kalli- words which I think beat even
your made-up ones for bizarreness. My favourite has to be:

kallizonos – 'with beautiful girdles'

Madonna perhaps?

A good computing one would be:

kallibotrus – 'with beautiful clusters'

!

kallikodikos - 'with beautiful code'

Note: That's not a classical Greek word. Maybe I should name a company
that :).

James A. Fortune
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top