473,403 Members | 2,284 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,403 software developers and data experts.

How can I list all records in a table at once on a form, and then enter data?

269 256MB
I am almost embarassed to ask this question but I can't figure it out...

I want to build a simple database where I track the overtime for 17 employees. I have two tables: tblEmployees (only contains a list of names) and tblHours (where I will put overtime hours). I had originally just put this all in one table but after I couldn't make it do what I wanted I split the tables. The reason I decided to split the table was because the hourly information will repeat weekly but the employees list will be constant. I can go back to one if recommended.

What I want to do is have a form where it lists all 17 employees at one time, so the supervisor can make one pass and record all the hours for all the employees for one day on one form. (Think of an Excel sheet.) Problem one is I can't get all the employees to show up down the form. The form just has one blank, I guess waiting for me to type in an employee name. (I don't want to type in. I just want it to be there, all 17, one after the other.)

So when I get this accomplished, I will want to enter overtime for Friday, Saturday, and Sunday every week. I plan to enter Friday first. After my first Friday's entry, how would I clear the form, saving Friday's entry, and start all over to enter Saturday?

Thanks in advance. :-)
Aug 30 '13 #1
7 1802
Seth Schrock
2,965 Expert 2GB
You will need to create a loop in VBA that goes through each employee record. Inside this loop, you would need to create a record in table that tracks the hours that would include the employee id and then just put 0 as the overtime hours as well as the date for which the overtime is being entered. Then all the supervisor needs to do is go through the list and change the overtime values from 0 to the correct value.
Aug 30 '13 #2
DanicaDear
269 256MB
Thanks Seth! Any hints on how to write the VBA to do that? I don't know how to write VBA, although I have learned from Bytes how to understand it somewhat.

These are the fields I want to collect for each employee for each day.
Date_of_OT (This will be the same for all 17 employees in one pass so I had hoped to enter in the top of my form and have the default in the 17 other fields set to copy that text box in the top, so as not to have to enter the date 17 more times)
Available_Hours (This will be the same for all 17 employees in one pass so I had hoped to enter in the top of my form and have the default in the 17 fields set to copy that text box in the top, so as not to have to enter it 17 more times)
Hours_Worked (changes per employee)
Required (changes per employee) (This let us know if the overtime worked was optional or required.)

Could a continuos form help me instead of VBA?
Aug 30 '13 #3
DanicaDear
269 256MB
I thought this would be easy, but the more I play with it the more I think it isn't. (No wonder I couldn't come up with a simple solution...)

I think I'll just use a form with a subform and the user will just have to arrow through all 17 entries...

If anyone has further tips, I'm happy to try things out.
Aug 30 '13 #4
Seth Schrock
2,965 Expert 2GB
Well, you will have to make several changes to make it fit your tables, but I can provide a framework for you. Warning, this is air code and is untested, so it may contain errors. Just post the exact message and number of the error as well as which line gets highlighted if you do get any errors.
Expand|Select|Wrap|Line Numbers
  1. Dim db As DAO.Database
  2. Dim rstEmp As DAO.Recordset
  3. Dim rstHours As DAO.Recordset
  4.  
  5. Set db = CurrentDb
  6. Set rstEmp = db.OpenRecordset("tblEmployees", dbOpenDynaset)
  7. Set rstHours = db.OpenRecordset("tblHours", dbOpenDynaset)
  8.  
  9. With rstEmp
  10.     Do While Not .EOF
  11.         rstHours.AddNew
  12.  
  13.         rstHours!EmployeeID_fk = !EmployeeID_pk
  14.         rstHours!Date_of_OT = Me.DateFieldOnForm
  15.         rstHours!Hours_Worked = 0
  16.         rstHours!Required = False
  17.  
  18.         rstHours.Update
  19.         .MoveNext
  20.     Loop
  21. End With
  22.  
  23. Set db = Nothing
  24. Set rstEmp = Nothing
  25. Set rstHours = Nothing
Lines 6 & 7 need the table names changed, line 13 needs the correct field names (EmployeeID_fk is the foreign key field in the hours table and EmployeeID_pk is the primary key field in the employee table). Line 14 needs the correct control name.
Aug 30 '13 #5
DanicaDear
269 256MB
Do I just make a form with my 5 fields ("Name" from tblEmployee and the other 4 fields from tblHours) and paste this code in the On Load event?
(Sorry for so many questions)
Aug 30 '13 #6
DanicaDear
269 256MB
Ok, I tried out what I asked in my last question.
The code executed with no errors. The "0" was insert as the code instructed.

However, the list of 17 employees did not appear down the left hand side (and therefore I couldn't fill in the 2 fields ["Hours_Worked" and "Required"] needed for each individual). However, it did save 17 records in tblHours when I dirtied the form. :-)

Also, it did not save the master date and master hours data (two fields same for everybody) in tblHOURS with the other data it saved automagically. Upon looking further though I didn't see a reference in the code for Hours_Master (the number of available OT hours) to copy into the tblHours. I feel like you could save so much time by peeking into my database. Is there a way I can attach a screen shot, or even the DB itself??

I think you're on the right track....(I'm impressed how you experts take our problems and wrap them up into code!).

Here's my current code with updated fields:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Form_Load()
  4. Dim db As DAO.Database
  5. Dim rstEmp As DAO.Recordset
  6. Dim rstHours As DAO.Recordset
  7.  
  8. Set db = CurrentDb
  9. Set rstEmp = db.OpenRecordset("tblEmployees", dbOpenDynaset)
  10. Set rstHours = db.OpenRecordset("tblHours", dbOpenDynaset)
  11.  
  12. With rstEmp
  13.     Do While Not .EOF
  14.         rstHours.AddNew
  15.  
  16.         rstHours!Name = !Name
  17.         rstHours!Date_of_OT = Me.Date_Of_OT_Master
  18. 'should Hours_Master be referenced here so it will update?
  19.         rstHours!Hours_Worked = 0
  20.         rstHours!Required = False
  21.  
  22.         rstHours.Update
  23.         .MoveNext
  24.     Loop
  25. End With
  26.  
  27. Set db = Nothing
  28. Set rstEmp = Nothing
  29. Set rstHours = Nothing
  30.  
  31. End Sub
Aug 30 '13 #7
Seth Schrock
2,965 Expert 2GB
Well, there are a couple of options for how to run this code. What I would probably do would be to Create a form that was unbound that would have your Me.Date_Of_OT_Master control as well as a button that when clicked would run the code and a subform that would contain the data that needs viewed. At the bottom of the button's OnClick event, you would need to requery the subform so that it could view the data that has been added.

And you answer your comment on line 18, you would enter a line for the Hours_Master on that line to set it to your value.
Aug 30 '13 #8

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

Similar topics

1
by: jbroome | last post by:
I have several tables that contain the same information as Identifying records but then with additional info that differs from table to table. e.g. 1 database of school students with their...
0
by: Jason | last post by:
I have a primary form which is used to enter/edit data in a table named Test_Results. On this primary form there is a subform which displays site addresses. This subform is linked to the primary...
2
by: filbennett | last post by:
Hi Everyone, I'm generally unfamiliar with Access form design, but have programmed Cold Fusion applications for a couple of years. I'd like to build a data entry form in Access that allows the...
0
by: mlarson | last post by:
I have a program that worked fine then they needed to be able to also see the empty cells (inmate cells) on a housing unit when they ran the query. So what I had to do was take two tables and...
1
by: savas_karaduman | last post by:
There is a subform embedded into a Main Form... Subform is standing for entering data into a table... There is a combobox on the Main Form... How Combo Box value can be added into table to which...
1
by: kellyj | last post by:
Hi My problem is i have 5 tables with diffirent fields in each, I have IDNum as a common field in each and i want to creat a form to enter data to these tables. any help would be a great help ...
4
by: billa856 | last post by:
Hi, My project is in MS Access. In that I have one Form(DataEntry) which I am using for entering data into the Table(PRODUCTION). Now after entering data in Textboxes when I click on...
4
by: AdamOnAccess | last post by:
I find that I always need to incorporate something like this into my forms, but I've never been happy on how I do it. Can someone advice me on the proper way to do this in Access. Let's say I have...
3
by: mark007 | last post by:
I want to open a table from switchboard in datasheet view to enter data, can anyone please guide me how it can be done, i created a form for the table and tried to open it from switchboard but it...
1
by: btoussaint | last post by:
We have two tables in that control some different data. Table one is dbo_ProductModel. Table two is dbo_CustomerInformation. Table three is dbo_WebInformation. I created the form from the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.