GrandmasterB
New member
- Local time
- Yesterday, 16:06
- Joined
- Jan 26, 2009
- Messages
- 9
Ok, folks, I have a custom database that I'm trying to update at my company.
On my Jobs entry form there is a button that "submits" new jobs a salesperson enters to the proper people internally via email notification. This part isn't elegant, but it works.
I want to add to that button a routine that checks the current CustomerID's open invoices, finds the oldest one, and compares that to that CustomerID's Terms for Payment field in the Customer table.
So far, I've been able to add the following:
I think TermsCheck should be an integer, but that is a story for another time.
Anyway, that piece of code returns the proper terms just fine (usually 30 days).
Now, what I need to do next sucks, as far as I can tell. I wrote the following query using the query builder to find the oldest invoice, and then viewed it as SQL code. It returns the proper oldest invoice as listed in the tblInvoice invoicing table, linked across the tblJobsSub (holds info on individual visits to a particular location) table through the parent tblJobs table (holds the information on a particular location with the customer's info) through to the tblCustomers table (which holds info on the customer who could have many sites):
...for customerID "2497A".
How in the hell do I write the VB code that does what this SQL statement does, stores that max invoice age somewhere, and then compares it to the terms?
If I can do that, I can come up with an if/then statement a la:
Can anybody help me, or do I need to take a class or something?
Thanks!
On my Jobs entry form there is a button that "submits" new jobs a salesperson enters to the proper people internally via email notification. This part isn't elegant, but it works.
I want to add to that button a routine that checks the current CustomerID's open invoices, finds the oldest one, and compares that to that CustomerID's Terms for Payment field in the Customer table.
So far, I've been able to add the following:
Code:
Dim TermsCheck As Variant
TermsCheck = DLookup("terms", "tblcustomers", "customerID ='" & Me.Parent.CustomerID & "'")
Anyway, that piece of code returns the proper terms just fine (usually 30 days).
Now, what I need to do next sucks, as far as I can tell. I wrote the following query using the query builder to find the oldest invoice, and then viewed it as SQL code. It returns the proper oldest invoice as listed in the tblInvoice invoicing table, linked across the tblJobsSub (holds info on individual visits to a particular location) table through the parent tblJobs table (holds the information on a particular location with the customer's info) through to the tblCustomers table (which holds info on the customer who could have many sites):
Code:
SELECT tblJobs.CustomerID, Max(DateDiff("d",[invoicedate],Date())) AS [Days Old], tblInvoice.Total, tblInvoice.AmountReceived
FROM (tblJobs INNER JOIN tblJobsSub ON tblJobs.JobNo = tblJobsSub.JobNo) INNER JOIN tblInvoice ON tblJobsSub.SubID = tblInvoice.SubID
GROUP BY tblJobs.CustomerID, tblInvoice.Total, tblInvoice.AmountReceived
HAVING (((tblJobs.CustomerID)="2497A") AND ((tblInvoice.Total)<>0) AND ((tblInvoice.AmountReceived) Is Null Or (tblInvoice.AmountReceived)<[total]));
How in the hell do I write the VB code that does what this SQL statement does, stores that max invoice age somewhere, and then compares it to the terms?
If I can do that, I can come up with an if/then statement a la:
Code:
If MaxInvoice > TermsCheck Then
MsgBox "Your customer sucks at paying, this job cannot be submitted"
Exit Sub
Else
...continue on with submission process
End If
Thanks!

Last edited: