Milestones Professional Automation: Microsoft Access VBA Examples
Warning: The information on these pages should only be used by software developers who are familiar with a Windows programming environment. KIDASA does not take responsibility for any damage caused to your information or computer due to programming errors.
Access VBA Example #1
Here’s an example of how you might use Milestones Professional’s OLE Automation to take information from an Access Table and generate a formatted project schedule. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The “ScheduleData” Access table: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The Milestones Professional Schedule: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The Access Visual Basic Program: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Here’s a Visual Basic Program that generates an outlined Milestones Professional schedule using the data in the Access table. The Milestones OLE calls are displayed in red. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Public Sub CreateSchedule()
‘ this function updates the schedule using data from a table Dim dbsCurrent As Database ‘Identify the table With objMilestones TaskNumber = 0 ‘Start of loop
On Error GoTo SkipDate ‘Use Milestones Professional OLE Automation calls to add symbols to the schedule .AddSymbol TaskNumber, Format(rstTable1!StartDate, “mm/dd/yy”), 1, 1, 2 .SetOutlineLevel TaskNumber, rstTable1!OutlineLevel SkipDate:
‘ End of loop.
‘Close Access Table ‘Keep Milestones Professional schedule open Exit Sub End Sub |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
To try this example: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Click here to download a self-extracting EXE file containing: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
– The Access Database (AccessExample.mdb) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
– The Milestones Professional Template (AccessTemplate.mtp) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(This download is recommended for experienced Access users with some programming knowledge.) |
Access VBA Example #2
This example shows how you might display a Milestones Professional schedule based on data in a Microsoft Access database. The same technique can be applied to other database systems. | |||||||||||||||
In this case, the MS Access database includes 3 tables (table1, table2, and table3). When the Main() sub is executed (in the Milestones module), a form is presented. It is initially populated with a schedule using dates from table1. From then on, the user can press one of 3 buttons labeled “Table1”, “Table2”, or “Table3” and cause Milestones to change the picture which is displayed.
This is accomplished by keeping a Milestones Professional schedule object open while the MS Access application is open and closing it when the MS Access application closes. While open, when the user presses one of the button, the software will:
|
|||||||||||||||
(We are not experts at MS Access programming. This example is offered to illustrate the use of Milestones Professional interface calls and give you ideas for your programming projects. This code is not complete and is not meant to be used as part of any of your projects.) | |||||||||||||||
The Form: | |||||||||||||||
![]() |
|||||||||||||||
The Access Visual Basic Program: | |||||||||||||||
Public dbsCurrent As Database Public rstTable1 As Recordset Public numberoftasklines As Integer, numpages As Integer Public x As Integer Public x2 As Integer Public TaskNumber As Integer Public objmilestones As Object Public StartDate As String, finishdate As String, schedulestartdate As String, schedulefinishdate As String Public xDatediff As Long Public title As String Public selectedtable As String Sub main() Set rstTable1 = dbsCurrent.OpenRecordset(“table1”, dbOpenTable) formatmilestonesschedule Form_Form1.showstuff End Sub Public Sub CreateSchedule() schedulestartdate = “12/31/2399” ‘ this function updates the schedule using data from a table With objmilestones ‘check Milestones object and see if it has been used. ‘color the rows differently depending upon which table is selected On Error GoTo done finishdate = Format(rstTable1!EndDate, “mm/dd/yy”) .AddSymbol TaskNumber, StartDate, 1, 1, 2 done: ‘ Put up a title and set the schedule’s start and end dates ‘ Create a bitmap with the new schedule ‘ pause to give bitmap time to save before going on Exit Sub End Sub Sub closeout() ‘Keep Milestones, schedule open End Sub Sub timeout() Dim PauseTime, Start, Finish, TotalTime objmilestones.setcolumnproperty 2, “Width”, 1.6 objmilestones.setcolumnproperty 11, “Width”, 1 objmilestones.setcolumnproperty 12, “Width”, 1 |
|||||||||||||||
In the Form1 Module: | |||||||||||||||
Option Compare Database Private Sub Command4_Click() Set Milestones1.rstTable1 = dbsCurrent.OpenRecordset(“table2”, dbOpenTable) Milestones1.CreateSchedule Private Sub Command5_Click() Milestones1.selectedtable = “table1” Image3.Picture = “c:milestones.bmp” End Sub Private Sub Command6_Click() Set Milestones1.rstTable1 = dbsCurrent.OpenRecordset(“table3”, dbOpenTable) Image3.Picture = “c:milestones.bmp” Public Sub showstuff()
Private Sub Command7_Click() |
|||||||||||||||
To try this example: | |||||||||||||||
Click here to download a self-extracting EXE file containing the above code. | |||||||||||||||
(This download is recommended for experienced Access users who are also experience programmers.) |