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

Using Variable data from a Form as Field Names

Using Access - I have a table where there is one field for each Weekend (field names are Week 1, week 2 and so on till Week 52), so I have 52 fields. I have a form that has 4 text boxes. Depending on the current weekend date, the boxes are for the current week and the next 3 weeks. Work percentages are added to each of the 4 boxes and need to be saved to the Weekend field in the table. So this week we would be saving data in Week01,Week02,Week03 & Week04. Next week we would be saving data in Week02,Week03,Week04 & Week05. How do I pass the data to the correct field each week. Is there VBA code that will let you pass the field name as a variable.
Jan 5 '18 #1

✓ answered by Seth Schrock

The Recordset.Fields() property allows you to pass the field name as a string and then assign or return a value.

However, you should look into Database Normalization and Table Structures. A properly designed table would have each week as a separate record instead of a separate field. You would want a primary key field (it could be an auto number field), a week number field, the value field, and if you need it, a foreign key field to link to another table. You would then just have a query return the weeks that you need and then input the values in each record and then the problem that you are currently having will no longer be an issue.

5 2324
Seth Schrock
2,965 Expert 2GB
The Recordset.Fields() property allows you to pass the field name as a string and then assign or return a value.

However, you should look into Database Normalization and Table Structures. A properly designed table would have each week as a separate record instead of a separate field. You would want a primary key field (it could be an auto number field), a week number field, the value field, and if you need it, a foreign key field to link to another table. You would then just have a query return the weeks that you need and then input the values in each record and then the problem that you are currently having will no longer be an issue.
Jan 5 '18 #2
NeoPa
32,556 Expert Mod 16PB
Seth's answer is almost perfect. I almost replied with a simple quote of the title with a comment of :
"That seems like a very bad idea."

Obviously I'd have included something more helpful too, but it looks like Seth's got you fully covered already.
Jan 5 '18 #3
Seth, Thank you for your comments. I like the ideal. There is a key field for each record. If I only use one field each in the table for Week No, Weekend Date and Percent then how would the user add in current week info plus est percent for the next three weeks. Each entry would get it's own records. Would they have to do 4 new records one at a time. The table also have fields for Project Name,Status, Start Date and Go-live Date. Would the user have to key in the other info each time also. Thank you for your help.
Jan 5 '18 #4
Seth Schrock
2,965 Expert 2GB
It is hard to really be specific without knowing exactly what you are trying to track, but let me give you an example.

Let's say that you are a teacher and every week you give your students (there just happens to be four of them) an assignment. Each assignment will have a name, a status (open, closed, etc.), a start date and a due date. Each student will be given a grade, a date completed, and a status (not started, completed, etc.). So in this example, you have two parts: many students' grades to one assignment. This is known as a one-to-many relationship and involves two tables.

Expand|Select|Wrap|Line Numbers
  1. tblAssignments
  2. AssignmentID
  3. AssignmentName
  4. Status
  5. StartDate
  6. DueDate
Expand|Select|Wrap|Line Numbers
  1. tblGrades
  2. GradeID
  3. AssignmentID
  4. StudentName
  5. CompletionDate
  6. Status
  7. Grade
You will notice that tblGrades has a field called AssignmentID. That is a foreign key field that links to the primary key field in tblAssignments. That is what ties the grades to the specific assignment. Now, the idea is to take away duplicated information. For example, you wouldn't put the assignment due date in the tblGrades because it would be the same for each student for that assignment, so you put it in the "one" side of the relationship.

Now to get back to your situation, you can think of each week percent as a grade and your group of four weeks as an assignment. Your job would then be to decipher which fields need to be on the "one" side and which need to be in the "many" side of the relationship. Make sure that you read the article that I linked to in my previous post.

Also keep in mind that there is often room for more tables than you originally think. For example, going back to the grades situation, you would probably want to not use the student's name in the tblGrades, but another foreign key field tied to a table with all the student information. Again, not knowing your data, I can't say that this would be the situation for you, but just keep your eyes open for the possibility.

Let us know if you have any more questions.
Jan 6 '18 #5
Seth, Thank you for your reply. I am working on a db that tracks projects. For each project there can be up to 5 different team members working on different parts of the project. Each week, each team members updates the per of time they spent on the proj that week and an est of how much time they will be spending over the next three weeks. The management team uses the info to make sure the workload is spread out to everyone and uses the est time to see if they need to bring in more staff or cut back staff.

I understand what you are talking about having two tables one for the project data and one for just the time update. I will go back and make the changes to my db. Thank you for your time.
Jan 8 '18 #6

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

Similar topics

5
by: Paul C-T | last post by:
Hi, Am I trying to be too clever here? I am trying to write a PHP page to enable me to enter values into a form then write those values to a text file. I want to use the form & table that...
7
by: JDS | last post by:
Hi, all. I'd like to do the following, preferably *without* resorting to JavaScript: I have a long, dynamically-generated form questionnaire. Not all of the form fields are dynamically...
0
by: Chris Sharman | last post by:
I'd like to design my pages to work cooperatively with browser autofill features. I've loked around, but can't find any good documentation on supported/unsupported field names...
3
by: Pavils Jurjans | last post by:
Hello, I have bumped upon this problem: I do some client-side form processing with JavaScript, and for this I loop over all the forms in the document. In order to identify them, I read their...
1
by: Jim | last post by:
Using VS 2005. I have bound fields on a form bound to a dataset(s) and I want to add various data elements to fields in the DB that are not comming from bound fields. This is what I have resorted...
1
by: Jonteeh | last post by:
I'm sure in VB6 I could call a field Me("TextBox") & Cstr(intBox) say for fieldnames "TextBox1" thru "TextBox80". Basically, I'm reading data from a comma delimited file and the first field in each...
1
by: John | last post by:
Hi I have two fields field1 and field2 on my form. Is there a way that the field names can be accessed via variable so that choice of the actual field to access is decided at runtime? Thanks...
2
by: beary | last post by:
I have a page with a form which has automatically generated fields, (which come from mysql column names). There could be any number of these fields, and I have no way of knowing exactly what they're...
6
by: ManningFan | last post by:
Got a little problem here... I have a combo box (Combo5) which needs to make a different field visible depending on the choice made. Standard code for what I'm doing is as such: If...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.