473,408 Members | 1,676 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,408 software developers and data experts.

Macro or VBA don't know which way to go to get outcome

I have a database that I have been stuck on for about 2 weeks now. I keep running in circles between macros and VBA code. Can't seem to figure out which way is going to work so thats the reason for the post.

Anyway the rundown is I have a table that has a persons report date formatted as a medium date and I have a field in that table that has MonthsOnBoard. What I am trying to do is create a macro or a function that will go through each person in the personnel table and calculate total months since they have reported and store it in MonthsOnBoard.

I have been able to do some what of the right calculation by adding in a datediff function in a text box on a report but thats not where I need this information at least not for now.

Table Structure
Personnel-->[Name]
[Report Date]
[MonthsOnBoard]

Thanks for everyones help in advance.

Thechazm
Oct 19 '08 #1
5 1320
DonRayner
489 Expert 256MB
I have a database that I have been stuck on for about 2 weeks now. I keep running in circles between macros and VBA code. Can't seem to figure out which way is going to work so thats the reason for the post.

Anyway the rundown is I have a table that has a persons report date formatted as a medium date and I have a field in that table that has MonthsOnBoard. What I am trying to do is create a macro or a function that will go through each person in the personnel table and calculate total months since they have reported and store it in MonthsOnBoard.

I have been able to do some what of the right calculation by adding in a datediff function in a text box on a report but thats not where I need this information at least not for now.

Table Structure
Personnel-->[Name]
[Report Date]
[MonthsOnBoard]

Thanks for everyones help in advance.

Thechazm
As long as you can perform the formula on you data to get the information then it's kind of redundant to store the result in another location. You could for example use the same formula in an unbound text field on a report or you could use it in a query.... etc.

Where do you want the data? and what do you want to do with it?
Oct 19 '08 #2
missinglinq
3,532 Expert 2GB
As Don has said, in most cases (including this one) calculations should not be stored but rather redone when needed. Typically this kind of thing would be done in a query, and then you base your form or reports on the query. You have the field in your table and query named ReportDate so, in your query, you make a calculated field. In a blank field enter the name of the calculated field, such as MonthsOnBoard then a colon then your expression/function:

MonthsOnBoard: DateDiff("m",[ReportDate],Date())

Now base your form/report on the query, and refer to MonsthsOnBoard as you would any other field. Any time you do this, the value you get for MonthsOnBoard will be up to date, because it will have just been recalculated.

Forms and reports are generally best based on queries, even when only one table is involved, because you can do this and other data manipulation.

Just remember, anytime you make this kind of change, be sure to change the RecordSource of your form/report to the query. Also remember any time you add a feild to your underlying table to go into design view for the query and add the field to the query.

Welcome to Bytes!

Linq ;0)>
Oct 19 '08 #3
NeoPa
32,556 Expert Mod 16PB
It sounds like you may get great benefit from reading Normalisation and Table structures.
Oct 20 '08 #4
Thanks for the information. I know its bad practice to store information in a table that should be updated all the time but since I am baseing a lot of functions off of these values and they only change a very few times a month I added an update when you first open the database to run the function.

Thanks all for your help and appreciate your time :)
Oct 21 '08 #5
NeoPa
32,556 Expert Mod 16PB
There are times when real life situations make following the "rules" blindly inappropriate. I would never treat rules as hard and fast. It sounds like you have a good understanding of the principles and WHY it's generally a good idea.

Anyway, pleased that all seems well now :)
Oct 21 '08 #6

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

Similar topics

25
by: Andrew Dalke | last post by:
Here's a proposed Q&A for the FAQ based on a couple recent threads. Appropriate comments appreciated X.Y: Why doesn't Python have macros like in Lisp or Scheme? Before answering that, a...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
5
by: Eric Lilja | last post by:
Using a macro, can I change what type an object is being cast to? I know, the initial respone to question might be an instinctive "ugly, don't even think about it!" or "don't use macros at all",...
4
by: tmountjr | last post by:
I've got a user who's trying to export a text file with unicode formatting. When he exports it as straight ascii, some of the foreign characters (mostly just accent marks and the like - no...
3
by: Charlie Zender | last post by:
Hi, I want to have a CPP macro that tests the value of a token and returns the string "No" if the token is undefined (or 0) and returns "Yes" if the token is defined (non-zero). Then I can...
6
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
37
by: junky_fellow | last post by:
hi guys, Can you please suggest that in what cases should a macro be preferred over inline function and viceversa ? Is there any case where using a macro will be more efficient as compared to...
3
by: swb76 | last post by:
Hi, I have 6 queries in Access that run great. They need to be run in sequence with the first 5 queries writing to tables and the sixth one pops up the final results in datasheet view. Now, how...
33
by: Peng Yu | last post by:
Hi, __PRETTY_FUNCTION__ is a macro that gives function name, etc. I'm wondering if there is a macro to get the class name inside a member function. Thanks, Peng
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.