473,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Using sql insert into statement with access VB in a timesheet db

Jerry Maiapu
259 100+
I am trying to create a simple clock in clock out (timesheet) in ms access. I have two tables (tblnames for staff names and tbldates for clocking times). tblnames has 2 fields namely id=autonumber,names =text. and tbldates has 4 fiels Id=autonumber,namesid=number, clockin=time/date and clock out =date/time.

the twos have a one to many relationship

I have a form that has a combo box that holds names of employees. in the same form i have a cmd button called "clock in" and another called "clock out"
Function:
The user selects the names from the combo box and when the the user clicks on the cmd clockin button the current date should be inserted into clockin field in the tbldates tables and and the cmd clockin button should be disable and the cmd clock out button should be enable.

When the user click clockout button the current date should be inserted into clockout field in the tbldates table. This becomes a single record in the tbldates tables and the next day the clockin and clock out dates/times should go in the second record of the tbldates tables.

I though of putting a sql "insert into" and "d look up" statement using VB so that when the user clicks on the clock in button the visual basic as to use the dlook up to cheeck if names (selected in the combo box) exist in table tblnmes and use to insert into statement to insert the corresponding (related) date -clockin and clock out values in its respective fields in the tbldates table.

The tables have one to many relationship so I could I go about inserting clock in clock out times into the tbldates table for the correct coresponding employeee .
I dont how to this in vb or whatever got the idea but hard to implemnt it..

How could I acheive this.

Attached is a screenshot of my desired form and some explaination....
Attached Images
File Type: jpg qst.jpg (20.4 KB, 559 views)
Feb 26 '10 #1
18 4952
TheSmileyCoder
2,322 Expert Mod 2GB
Is this a database located on a network, where everyone uses the same database? Is it located on a single PC? Will there be multiple users?

I think I have a good idea of what you want, but to better guide you, I would need some information on how you would intend to use this database and for what.
Feb 26 '10 #2
patjones
931 Expert 512MB
Here's what I did...

For the clock in button:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdClockIn_Click()
  2.  
  3. Dim qryUpdate As QueryDef
  4. Dim strSQL As String
  5.  
  6. Me.txtDateCurrent.SetFocus
  7.  
  8. strSQL = "PARAMETERS [Name] SMALLINT, [TimeIn] DATETIME; INSERT INTO tbldates (namesid, clockin) VALUES ( [Name], [TimeIn])"
  9.  
  10. Set qryUpdate = CurrentDb.CreateQueryDef("ClockIn", strSQL)
  11. qryUpdate("Name") = Me.cboNames
  12. qryUpdate("TimeIn") = Now
  13. qryUpdate.Execute (dbFailOnError)
  14.  
  15. cmdClockIn.Enabled = False
  16. cmdClockOut.Enabled = True
  17.  
  18. 'Clean up
  19. qryUpdate.Close
  20. CurrentDb.QueryDefs.Delete "ClockIn"
  21.  
  22. End Sub

For the clock out button:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdClockOut_Click()
  2.  
  3. Dim qryUpdate As QueryDef
  4. Dim strSQL As String
  5.  
  6. Me.txtDateCurrent.SetFocus
  7.  
  8. strSQL = "PARAMETERS [Name] SMALLINT, [TimeOut] DATETIME; UPDATE tbldates SET clockout = [TimeOut] WHERE namesID = [Name] AND clockout IS NULL"
  9.  
  10. Set qryUpdate = CurrentDb.CreateQueryDef("ClockOut", strSQL)
  11. qryUpdate("Name") = Me.cboNames
  12. qryUpdate("TimeOut") = Now
  13. qryUpdate.Execute (dbFailOnError)
  14.  
  15. cmdClockIn.Enabled = True
  16. cmdClockOut.Enabled = False
  17.  
  18. 'Clean up
  19. qryUpdate.Close
  20. CurrentDb.QueryDefs.Delete "ClockOut"
  21.  
  22. End Sub

For the combo box (to determine whether or not the person you picked is currently clocked in or out):

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboNames_AfterUpdate()
  2.  
  3. If IsNull(DLookup("[namesID]", "tbldates", " [namesID] = " & Me.cboNames & " AND clockout IS NULL")) Then
  4.  
  5.     Me.cmdClockIn.Enabled = True
  6.     Me.cmdClockOut.Enabled = False
  7.  
  8. Else
  9.  
  10.     Me.cmdClockIn.Enabled = False
  11.     Me.cmdClockOut.Enabled = True
  12.  
  13. End If
  14.  
  15. End Sub

Notice that an autonumber ID is not necessary in tbldates...instead, this method assumes that the person is either clocked in - in which case they have a record where clock out is null, or they are clocked out, in which case they have no records where clock out is null, and then DLookup returns null.

Also, namesID should NOT be set as a primary key in tbldates; otherwise Access won't allow you to have more than one entry for a particular person.

I quickly put together a form and tested this all out...seems to work fine. Let me know how it works out for you.

Pat
Feb 26 '10 #3
Jerry Maiapu
259 100+
@TheSmileyOne

Thanks. this databse will be put on a network after completion but at the moment am working on it on a laptop and definetly there will be multiple users.

I am a graduate Trainee trying to create a timeshhet database for emplyees in a NGO. This databse will be used by the employees to clock in and out and am also planing to put a cmd button to display/run report only such time the name in the comco box is the boss's name.

Thanks for for time and good heart to help..
Mar 1 '10 #4
Jerry Maiapu
259 100+
Pat you are the best... I needed this very much thanks alot for your coding. I'll try it out first..
Once again thanks..

Jerry
Mar 1 '10 #5
Jerry Maiapu
259 100+
@TheSmileyOne

Thanks. this databse will be put on a network after completion but at the moment am working on it on a laptop and definetly there will be multiple users.

I am a graduate Trainee trying to create a timeshhet database for emplyees in a NGO. This databse will be used by the employees to clock in and out and am also planing to put a cmd button to display/run report only such time the name in the comco box is the boss's name.

Thanks for for time and good heart to help..
Mar 1 '10 #6
TheSmileyCoder
2,322 Expert Mod 2GB
Once on the network, will each user use his own personal PC, or shared PC's to access the database?

How do you intend to handle people forgetting to punch in/out?
Mar 1 '10 #7
patjones
931 Expert 512MB
That sounds great Jerry. My solution is intended to be the minimum functionality that you require. As Smiley says, you will probably want to put in other features to make it more user friendly - like handling the case of forgetting to clock in or out.

It also would not be a huge leap to have the employee clock in/out by entering some kind of employee ID. As it stands now anyone could pick any name from the drop-down list and clock them in or out at will. Having an ID that each employee enters makes it more secure.

Let us know how it goes.

Pat
Mar 1 '10 #8
Jerry Maiapu
259 100+
Ok thanks guys for guiding me through. I am almost complete with the clock in/out form.

Attached is a screen shot of my login form and the clocking form.

One of my colleagues helped to have the log in form with username, password and domain from the windows login details to log into the database. Which is pretty cool. (See attached screen shoot)

On the timesheet form whenever the manager logs in the navigation and other buttons are enabled. Currently in the screen shot it is disabled.
If I need help in creating reports or any other thing Ill say so but for now you help me with this problem scenario?

What I want to do is when the wrong user name or password is entered instead my msgboxes telling users to re enter the correct names I would like to prompt that message in a tool tip (balloon) pointing to the correct textbox instead of the msgboxes because it quite irritating to see these msgboxes popping every now and then and pressing ok button several times.
The tool tip can be useful in displaying my messages for example when the user clocks in the tool tip can point to the clock in time with the message like “You just clocked in”

Please can one of you guys help me out if you can. I’ve pretty no idea..

Thanks in advance

Jerry

One more thing…..do any one of you know how to minimise the access window to the system tray and when double clicked it can pop up (maximised)

Sorry for a lot of things but this is what I would like to do:
When a user clocks in and press a ok button the access window minimises to the system tray (notification area) if the user forgets to clock out and shuts down or logs off the computer
I will create a pop up msgbox (vbyesno) that will prevent the close (unload) of clock in form if the user does not clock out (doesn’t matter weather it is the access application or the windows os itse trying tot unload the clockin form lf the dialogue pop up msgbox can message can still stop anything from closing the form unless the user press No to exit.

This will only happen if the access application is still running and that is why I want someone to help minimise the window to the system tray. If minimised to the task bar anybody can accidentally maximise when dealing with other application on the task bar..

Thankyou


Jerry M
Mar 4 '10 #9
patjones
931 Expert 512MB
Jerry -

The closest built-in thing that Access has to a balloon is the ControlTip property. This is basically just a box that pops up when you hover over a control, and displays whatever text you specify in the property. I am lazy about using these in my own projects, but it is a good practice to get into because it helps the people who will be using your application.

However, for what you are looking for...I think you need to find an ActiveX balloon control which can be downloaded and added in to your copy of Access. There are many vendors online which have such controls. Here is one example out of many that I found: http://www.softspecialist.com/Balloo...alloon-OCX.htm.

For minimizing Access to the Windows tray, I think what you need is a Windows API call in your VBA code. For instance: http://social.msdn.microsoft.com/For...7-c54b61cf13de

Hope this helps.

Pat
Mar 4 '10 #10
Jerry Maiapu
259 100+
Thanks Zepphead.

Would you mind telling me (show me with an example) on how I would program it (using VB) or I mean how do I use the Active x balloon control to point to a textboxes when a button is clicked on a cmd button..Give a sample please..

Thanks you so much

Jerry
Mar 8 '10 #11
Jerry Maiapu
259 100+
Ok thanks guys for guiding me through. I am almost complete with the clock in/out form.

Attached is a screen shot of my login form and the clocking form.

One of my colleagues helped to have the log in form with username, password and domain from the windows login details to log into the database. Which is pretty cool. (See attached screen shoot)

On the timesheet form whenever the manager logs in the navigation and other buttons are enabled. Currently in the screen shot it is disabled.
If I need help in creating reports or any other thing Ill say so but for now you help me with this problem scenario?

What I want to do is when the wrong user name or password is entered instead my msgboxes telling users to re enter the correct names I would like to prompt that message in a tool tip (balloon) pointing to the correct textbox instead of the msgboxes because it quite irritating to see these msgboxes popping every now and then and pressing ok button several times.
The tool tip can be useful in displaying my messages for example when the user clocks in the tool tip can point to the clock in time with the message like “You just clocked in”

Please can one of you guys help me out if you can. I’ve pretty no idea..

Thanks in advance

Jerry

One more thing…..do any one of you know how to minimise the access window to the system tray and when double clicked it can pop up (maximised)

Sorry for a lot of things but this is what I would like to do:
When a user clocks in and press a ok button the access window minimises to the system tray (notification area) if the user forgets to clock out and shuts down or logs off the computer
I will create a pop up msgbox (vbyesno) that will prevent the close (unload) of clock in form if the user does not clock out (doesn’t matter weather it is the access application or the windows os itse trying tot unload the clockin form lf the dialogue pop up msgbox can message can still stop anything from closing the form unless the user press No to exit.

This will only happen if the access application is still running and that is why I want someone to help minimise the window to the system tray. If minimised to the task bar anybody can accidentally maximise when dealing with other application on the task bar..

Thankyou


Jerry M
On how to handle cases of forgeting to log out, if you have any ideas/sample databse/Vba/sql etc.. please give
Mar 8 '10 #12
Jerry Maiapu
259 100+
Hi zepphead80 ,
When minimised it does not respond. Access application is frozen.. Don know what to do ..any Idea..zepphead80 ?

Jerry
Mar 8 '10 #13
patjones
931 Expert 512MB
Jerry -

Sorry, I'm just not experienced enough with Windows API calls to be able to help you with this. Hopefully there is someone else on the forum here with the insight you need to work through the issue.

Pat
Mar 8 '10 #14
Jerry Maiapu
259 100+
I have a date field of tbldates that records/captures date from a form txtbox.
In the same table (tbldates) has this clockin clock out times.
Question
if the user forgets to clock out then (ie clockout field will be null) How can I pop up a msg box that tell the user (the next day ....not next time same day... when access starts ) he did not clock out yetreday.. Other than yesterday if the clockin field is null for days after yesterday should not be accounted for..

What I did/thought..

Because on the clock in form 3 txtboxes are shown ( dateclockin,txtclockin,txtclockout)

this is what it to do..

1 on open (ie form open) go to last record
2. chech if date is yesterday
3 if yesterday then check txtclockout is null or empty
4. if empty then pop up msgbox message "you did not clock out yesrday"
5.else go to new record
can some give me the code for this

thanks
problem wth step 3
Ta Jerry
Mar 11 '10 #15
patjones
931 Expert 512MB
I'm confused about why you are checking to see if it was yesterday. What if someone forgets to clock out Friday evening? They still need to get the message Monday morning when they go to clock in. Don't you really just need to check and see if there is a record with a null clock out time, no matter what day it is?

Pat
Mar 11 '10 #16
Jerry Maiapu
259 100+
Thank you for the direction.
What I meant was that we used to have power black out normally during the day so at times users might not clock out if stanby gen doesnt work. that is why I wanted to check thier clock out status so that they can enter the right clock out time the next day. Like you said I can check every days but the problem is with my table realtionship I have a one(tblusers) to many(tbldatetime) relationship and if it needs to check then it will check the entire field with previous dates. Don know what to do
Edit relationship?

Please help Ta..
Mar 12 '10 #17
patjones
931 Expert 512MB
Let me ask you this. Suppose I clock in Wednesday morning. Then the power goes out Wednesday afternoon and I cannot clock out. Thursday morning when I come in and choose my name from the combo list, what should happen?

The way I wrote my code back in post #3, the clock in button would be disabled because I still have a record with a null clock out time (the record from Wednesday).

I'm getting the sense from you that you still want the employee to be able to clock in even though Wednesday's clock out is still null. If that's the case, how do you want to fill in the clock out time from Wednesday?

I don't think the relationship between the tables should present a problem here. Remember, tblUsers is really just a "look up" table that tells you what the employee's name is.

I think we are going in the right direction with this, but we just need to figure out what to do when someone tries to clock in without having previously clocked out.

Pat
Mar 12 '10 #18
Jerry Maiapu
259 100+
Hi Zepphead80,
I thankyou for guiding me through. I have completed the timesheet and now they are using it. However recently, I found out that for public holidays or power disruption the person with administrative privilege can clock in or clock out for all of the employees at a particular day.
How can I make it possible for him to just enter
1. Clockin time
2. Clockout time and
3. Date

..on a form so that when he clicks on a cmdupdate button, it will put the dates and times into its respective fields in the table for all the employess.

I have two tables tblemplyees and tbltimesheet. They have a one to many relationship:

I can use insert into statement but the problem is:
First I have to check the correct names in tblemplyees table and insert into the tbltimesheet the dates and the clockin and clock out times.

How can I achieve this? Please help..

A short table attributes

Table1

tblemplyees

eid autonumber (primary key)
efname text (first name)
esname text (second name)

…………………………………………..
Table 2
tbltimesheet
tid autonumber (primary key)
eid number (foreign key)
date date/time (date clocked in)
clockin date/time (time clocked in)
clockout date/time (time clocked out)
Apr 12 '10 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: harsha mogaligundla | last post by:
Dear All , I am trying to develop a web based electronic Timesheet system for the payroll department using ASP and SQL server, the front end has fields like ssn,time -in , tim-out,regular...
2
by: ImraneA | last post by:
Hi there Application : Access v2K/SQL 2K Jest : Using sproc to append records into SQL table Jest sproc : 1.Can have more than 1 record - so using ';' to separate each line from each other.
10
by: teddysnips | last post by:
Application is a Work Tracking/Timesheet database. The increments of work are stored in the TimesheetItem table. This contains, inter alia, the Work Code, the Start and the Duration that the...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
22
by: alecjames1 | last post by:
I have a form which the user must complete before closing. I have disabled the window x button and use my own exit button. When selected it checks to see if the user has completed the entries...
1
by: Kevin | last post by:
Hello experts, I'm a newbee to ASP.NET. And I have been struggling solving this problem. But I can't do it. Can you please help me get over this wall? Below is the code and error message: <%@...
2
by: Geoffrey KRETZ | last post by:
Hello, I'm wondering if the following behaviour is the correct one for PostGreSQL (7.4 on UNIX). I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching the following request :...
1
by: thebison | last post by:
Hi everyone, Quick question, I'm creating a Timesheet Application with ASP.NET C# in Visual Studio 2003. The database has been built using MSDE. I have followed the MSDN libraries guide to...
2
by: csgraham74 | last post by:
Hello, im using MS Access as a front end to link to MYSQL. although this is possibly an Access issue i thought someone would be able to help me. the error message "ODBC--insert on a linked table...
8
by: Roland Hall | last post by:
In Access you use "*" + + "*", + can be replaced with & Calling a parameterized query in Access requires % be used in place of *, however, all that I have read show dynamic SQL passed to Access: ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.