Grrr I just lost the post so have to start again, I hope I don't miss anything!
Hello!!!
Ok, so I have a database (MS Access 2003), which has a Jobs table and has information about the client, client contact, job descriptions and most importantly:
InvoiceDate
InvoiceNumber
JobRate
JobExpenses
JobPayment
PaymentTerms
PaymentDueDate
InvoiceSent (checkbox)
Invoice sent will always be the same day as InvoiceDate, so no need for a text field, all others are.
So what I am trying to work out is how to calculate the PaymentDueDate, which has now been changed to 28 days from the Friday of the week the job finishes. So for example, if I finished a job on Monday 4 December 2006, my payment due date would be 28 days from Friday 8 December 2006.
I can no longer use [InvoiceDate}+28 to get this due date.
Any ideas?
7 1371 NeoPa 32,556
Expert Mod 16PB
Try : - [PaymentDueDate] = [InvoiceDate] + 35 - WeekDay([InvoiceDate])
InvDate + (7-WeekDay(InvDate)) + 28.
Thank you NeoPa,
Do you have a 'writing code for dummies version'?
I'm not sure where I am supposed to be putting this code. I initially placed it within the OnOpen routine for the form and that didn't work. I ied to insert it as the Control Source of the textfield and that didn't work either.
Should I even be trying to place this on the form? Or should it go on the table etc?
NeoPa 32,556
Expert Mod 16PB
Thank you NeoPa,
Do you have a 'writing code for dummies version'?
I'm not sure where I am supposed to be putting this code. I initially placed it within the OnOpen routine for the form and that didn't work. I ied to insert it as the Control Source of the textfield and that didn't work either.
Should I even be trying to place this on the form? Or should it go on the table etc?
I would put it in the AfterUpdate event of the control for the InvoiceDate.
You should use the form controls in your calculation rather than the record fields though.
Hi there NeoPa,
Geeeenius! Thanks!!!! That worked, but like this: - [JobPaymentDate] = [JobInvoiceDate] + 35 - Weekday([JobInvoiceDate])
-
'JobInvoiceDate (7 - Weekday(JobInvoiceDate)) + 28
The second line didn't seem to work, so I had to leave it as a comment - what is it supposed to do?
Also, is there a way to set a if JobInvoiceDate = Null then set JobPaymentDate = "" and do nothing (i.e. if I remove the invoice date, it should clear the payment due date)
As I inserted dates to test it, when I removed the date, the jobpaymentdate still had a date in there and I got an error message asking me to debug because the JobInvoiceDate field was empty (onAfterUpdate)
Does that make sense?
NeoPa 32,556
Expert Mod 16PB - [JobPaymentDate] = [JobInvoiceDate] + 35 - Weekday([JobInvoiceDate])
-
'JobInvoiceDate (7 - Weekday(JobInvoiceDate)) + 28
The second line didn't seem to work, so I had to leave it as a comment - what is it supposed to do?
The second line (being outside the code tags) was meant as a comment :).
Also, is there a way to set a if JobInvoiceDate = Null then set JobPaymentDate = "" and do nothing (i.e. if I remove the invoice date, it should clear the payment due date)
- [JobPaymentDate] = IIf(IsNull([JobInvoiceDate]), "", [JobInvoiceDate] + 35 - Weekday([JobInvoiceDate]))
Although if [JobPaymentDate] is a date field then a Null would probably fit better than an empty string. The original version would return a null in that case as any calculation involving a Null always resolves to Null.
As I inserted dates to test it, when I removed the date, the jobpaymentdate still had a date in there and I got an error message asking me to debug because the JobInvoiceDate field was empty (onAfterUpdate)
Does that make sense?
Check which fields in your table will accept a null value (Required property=No).
If you want to be able to have an empty field in some records then that's the way to do it.
Thank you very much! I definitely need to read up on Access event procedures as I tried that several times and it still didn't work. I did a small bit of VB in college, so came up with this: - If [JobInvoiceDate] <> "" Then
-
[JobPaymentDate] = [JobInvoiceDate] + 35 - Weekday([JobInvoiceDate])
-
Else
-
[JobPaymentDate] = ""
-
End If
And that somehow worked! Basic I know, but I can't seem to get my head around some of the other coding methods.
Thank you for all of your help, it was very useful!
NeoPa 32,556
Expert Mod 16PB
What you have there is roughly equivalent to what I had anyway and should work fine. Careful of putting empty strings (strings whether empty or not) in a date field though. This may throw up errors for you.
Lastly, the IIf() function I used is not absolutely necessary, but it is one of THE most useful functions ever invented (and essentially simpler in concept even than the If...Then...Else...End If construct. I cannot recommend strongly enough that you learn about it. IIf Function
Returns one of two parts, depending on the evaluation of an expression.
Syntax IIf(expr, truepart, falsepart)
The IIf function syntax has these named arguments:
Part Description expr Required. Expression you want to evaluate. truepart Required. Value or expression returned if expr is True. falsepart Required. Value or expression returned if expr is False.
Remarks
IIf always evaluates both truepart and falsepart, even though it returns only one of them. Because of this, you should watch for undesirable side effects. For example, if evaluating falsepart results in a division by zero error, an error occurs even if expr is True.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: BlackFireNova |
last post by:
I need to write a report in which one part shows a count of how many
total records fall within the working days (Monday - Friday) inside of a
(prompted) given date range, in a particular...
|
by: Patrick Fisher |
last post by:
Hi All
If I Take DateFrom from DateTo in a 31 day month I get 30 days because
31-1=30, is there a way of getting the correct answer without having
to us a lookup table?
Patrick
|
by: MAF |
last post by:
Is there a way through globalization to get the days of the week based on
culture?
|
by: Ricardo Perez Lopez |
last post by:
Hello everyone:
I'm a PostgreSQL newbie, working now with dates, times, timestamps and
intervals.
I have three questions about the above:
FIRST:
--------
|
by: tasmontique |
last post by:
I am working on an access 2002 flight schedule database. I am new to access but have some basic understanding of sql and vb6 code.
I have learned a lot from this website. Thanks much
Hopefully...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
| |