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

Extracting Useful Information From Contracts - VBA Code Example

153 100+
Hey guys...as a relatively new programmer, I try to give back where I can. Below is the code for a useful program I believe many of you could use...just don't use the same exact code because...well I don't work for myself if you get my drift....anyways even if this is not asked of you...it might get you on friendly terms with the lawyers in the office

The code is written to extract information from a table with contract information and divide it up into the number of days left until the end of the contract or required notification of renewal or non-renewal (and then information based off of that such as terms of late termination or what not) etc... The user is prompted to give a number of days notice before these events and based on the status the contracts that apply are divided into four tables such as contracts that have ended, contracts that require notification within that amount of days, contracts that will end in that number of days, and contracts that will end within that number of days but have passed their expiration. This is all done with VBA in a module instead of using querries...I feel more comfortable using VBA for some reason....Obviously you would have to create the tables and fields so the information can be inserted and customize it, of course, for your own purposes. I have added commentary to help you follow what I am doing if you are not very familiar with VBA as I was not just a short time ago...if you are still confused, some of the lessons from this site (http://www.functionx.com/vbaccess/Lesson01.htm) might help you follow along a little better. You might also want to add some security once you're fully finished so only certain users can edit the main contract folder. With this information you could export a report through event code in a form that would allow the user options such as exporting the report to word or excel or even offer both options....anyways here it is:

[PHP]Private Sub DaysToCompletion()

'Opening ADODB connections and record sets
Dim con1 As ADODB.Connection
Dim con2 As ADODB.Connection
Dim con3 As ADODB.Connection
Dim con4 As ADODB.Connection
Dim con5 As ADODB.Connection
Dim recSet1 As ADODB.Recordset
Dim recSet2 As ADODB.Recordset
Dim recSet3 As ADODB.Recordset
Dim recSet4 As ADODB.Recordset
Dim recSet5 As ADODB.Recordset
Set con1 = CurrentProject.Connection
Set con2 = CurrentProject.Connection
Set con3 = CurrentProject.Connection
Set con4 = CurrentProject.Connection
Set con5 = CurrentProject.Connection
Set recSet1 = New ADODB.Recordset
Set recSet2 = New ADODB.Recordset
Set recSet3 = New ADODB.Recordset
Set recSet4 = New ADODB.Recordset
Set recSet5 = New ADODB.Recordset
'setting records and connections to actual tables (and allowing editing capabilities to temporary tables but not the Contracts table)
recSet1.Open "tblContracts", con1, , adLockReadOnly
recSet2.Open "NotEndedPastRenewalX", con2, adOpenKeyset, adLockOptimistic
recSet3.Open "NotificationX", con3, adOpenKeyset, adLockOptimistic
recSet4.Open "ContractEndX", con4, adOpenKeyset, adLockOptimistic
recSet5.Open "ExpiredX", con5, adOpenKeyset, adLockOptimistic

Dim x As Long
'In context of the form this will open in, asking user for the number of days notification before contract end or notification or non-renewal (or renewal)
x = InputBox("Enter the number of days:")

'Declaring UntilCompletion as the amount of days until completion and UntilCompletion2 will be number of days until required notification
Dim UntilCompletion As Long
Dim UntilCompletion2 As Long

'Looping until EOF (until the last record for EndDate in tblContracts...so
'someone else would have declared recSet1.Open
'"tblWhateverYourTableNameIs", con1 which means
'connection1 and then to open a field in that recordset you type
'recSet1.Fields("fieldname"))

recSet1.MoveFirst
Do Until recSet1.EOF
' End Date must be in quotes or will not work
UntilCompletion = DateDiff("d", Date, recSet1.Fields("EndDate"))
UntilCompletion2 = DateDiff("d", Date, recSet1.Fields("NotificationDate"))
' For Debugging purposes...check in immediate window
Debug.Print x
Debug.Print UntilCompletion
Debug.Print UntilCompletion2

If UntilCompletion2 >= 0 And UntilCompletion2 <= x Then
'Must say rs.AddNew and rs.Update before and after updating fields
'Captures contracts that require notification within the next x number of days
recSet3.AddNew
recSet3.Fields("UntilNotification") = UntilCompletion2
recSet3.Fields("Vendor") = recSet1.Fields("Vendor")
recSet3.Fields("NotificationAddress") = recSet1.Fields("NotificationAddress")
recSet3.Fields("DateofContract") = recSet1.Fields("DateofContract")
recSet3.Fields("NotificationDate") = recSet1.Fields("NotificationDate")
recSet3.Fields("TermofContract") = recSet1.Fields("TermofContract")
recSet3.Fields("EndDate") = recSet1.Fields("EndDate")
recSet3.Fields("PaymentTerms/LateFees") = recSet1.Fields("PaymentTerms/LateFees")
recSet3.Fields("AutomaticRenewal") = recSet1.Fields("AutomaticRenewal")
recSet3.Fields("EarlyOutClause") = recSet1.Fields("EarlyOutClause")
recSet3.Update
End If

If UntilCompletion >= 0 And UntilCompletion <= x Then
'Captures contracts that end within the next x number of days
recSet4.AddNew
recSet4.Fields("UntilContractEnd") = UntilCompletion
recSet4.Fields("Vendor") = recSet1.Fields("Vendor")
recSet4.Fields("NotificationAddress") = recSet1.Fields("NotificationAddress")
recSet4.Fields("DateofContract") = recSet1.Fields("DateofContract")
recSet4.Fields("NotificationDate") = recSet1.Fields("NotificationDate")
recSet4.Fields("TermofContract") = recSet1.Fields("TermofContract")
recSet4.Fields("EndDate") = recSet1.Fields("EndDate")
recSet4.Fields("PaymentTerms/LateFees") = recSet1.Fields("PaymentTerms/LateFees")
recSet4.Fields("AutomaticRenewal") = recSet1.Fields("AutomaticRenewal")
recSet4.Fields("EarlyOutClause") = recSet1.Fields("EarlyOutClause")
recSet4.Update
If UntilCompletion2 <= UntilCompletion And UntilCompletion2 < 0 Then
'Captures contracts that end within the next x number of days but have expired
UntilCompletion2 = (UntilCompletion2 * (-1))
recSet2.AddNew
recSet2.Fields("PastRenewalDate") = UntilCompletion2
recSet2.Fields("Vendor") = recSet1.Fields("Vendor")
recSet2.Fields("NotificationAddress") = recSet1.Fields("NotificationAddress")
recSet2.Fields("DateofContract") = recSet1.Fields("DateofContract")
recSet2.Fields("NotificationDate") = recSet1.Fields("NotificationDate")
recSet2.Fields("TermofContract") = recSet1.Fields("TermofContract")
recSet2.Fields("EndDate") = recSet1.Fields("EndDate")
recSet2.Fields("PaymentTerms/LateFees") = recSet1.Fields("PaymentTerms/LateFees")
recSet2.Fields("AutomaticRenewal") = recSet1.Fields("AutomaticRenewal")
recSet2.Fields("EarlyOutClause") = recSet1.Fields("EarlyOutClause")
recSet2.Update
End If

ElseIf UntilCompletion < 0 Then
'Captures contracts that have expired and are presented in a table which the user can use in order to delete information they no longer need if they have proper access
UntilCompletion = (UntilCompletion * (-1))
recSet5.AddNew
recSet5.Fields("PastExpiration") = UntilCompletion
recSet5.Fields("Vendor") = recSet1.Fields("Vendor")
recSet5.Fields("NotificationAddress") = recSet1.Fields("NotificationAddress")
recSet5.Fields("DateofContract") = recSet1.Fields("DateofContract")
recSet5.Fields("NotificationDate") = recSet1.Fields("NotificationDate")
recSet5.Fields("TermofContract") = recSet1.Fields("TermofContract")
recSet5.Fields("EndDate") = recSet1.Fields("EndDate")
recSet5.Fields("PaymentTerms/LateFees") = recSet1.Fields("PaymentTerms/LateFees")
recSet5.Fields("AutomaticRenewal") = recSet1.Fields("AutomaticRenewal")
recSet5.Fields("EarlyOutClause") = recSet1.Fields("EarlyOutClause")
recSet5.Update

End If

recSet1.MoveNext
Loop

'Closing connections and clearing record sets
recSet1.Close
recSet2.Close
recSet3.Close
recSet4.Close
recSet5.Close
con1.Close
con2.Close
con3.Close
con4.Close
con5.Close
Set con1 = Nothing
Set con2 = Nothing
Set con3 = Nothing
Set con4 = Nothing
Set con5 = Nothing
Set recSet1 = Nothing
Set recSet2 = Nothing
Set recSet3 = Nothing
Set recSet4 = Nothing
Set recSet5 = Nothing
End Sub[/PHP]
Dec 19 '06 #1
4 2633
Kosmos
153 100+
No clue what's up with the color scheme
Dec 20 '06 #2
MMcCarthy
14,534 Expert Mod 8TB
No clue what's up with the color scheme
you used php instead of code tags. doesn't recognise the apostrophe as a comment.

Mary
Dec 20 '06 #3
Kosmos
153 100+
yeah...I figured...I just don't like the color scheme :) If I had used quotes it would have gotten rid of all the indents and those who were not familiar with what is going on would have been utterly confused.
Dec 20 '06 #4
Kosmos
153 100+
Thanks to the help of willakawill, I have added further functionality to this code...and Willakawill cleaned it up for an easier to read version. This new version adds outlook notification that is sent to outlook as an appointment after checking if it has already been added or not. Remember, this code was done by myself with the help of you guys and so it is only fair to give back and I like to give back anyways....but, it was created while in the employ of my company so you may only use it for reference whatever that means :)

The code can be found here: http://www.thescripts.com/forum/thread581521.html

Cheers :)

Kosmös
Dec 28 '06 #5

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

Similar topics

4
by: lecichy | last post by:
Hello Heres the situation: I got a file with lines like: name:second_name:somenumber:otherinfo etc with different values between colons ( just like passwd file) What I want is to extract...
2
by: Stephen Horne | last post by:
Just recently I decided I want to make use of my ISP freebie webspace. In order to make that easier, I'd like to be able to automatically synchronise an FTP file/folder heirarchy with one on my...
1
by: svilen | last post by:
hi. this was named but it is misleading. i want to have the order of setting items in intrinsic dicts (keyword args, or class attributes, etc). which is, a prdered dict trhat matches the...
0
by: Gnaneshwar Babu | last post by:
Hi I am facing a problem with extracting event logs of win32 to a file. Am using the following code to extract eventlogs to file use Win32::EventLog; $handle=Win32::EventLog->new("System",...
1
by: Trancedified | last post by:
Hello, I read through this thread regarding FindWindowEx vs. EnumChildWindows: http://www.xtremevbtalk.com/showthread.php?t=130418 It looks like it was done in VB6, can this be done in...
3
by: pratham | last post by:
Hi, I was seeing code of PetShop 2.0 and find is quite .. differnet design and architecture .. too much of clutter in classes .. order class using and Iorder and Iorder using an orderInfo and...
1
by: Nospam | last post by:
I am trying to have an expandable menu each time it's clicked expands, and if it's clicked again, if it is already expanded contracts, and if contracted expands, following this example...
6
by: rlntemp-gng | last post by:
I need to extract information from some Excel files but am stuck with part of it: As an example, I have the following Excel File that has 3 tabbed sheets: FileName: ...
1
by: final farewell | last post by:
Hello, I am using Ekhau Location Tracking System for an assignment. It is a system that is able to track configured tags attached to people or objects. I am new to the Ekahau Location Tracking...
0
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...
0
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
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
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...

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.