|
Navigation: Advanced Topics (click to see list) > Working With Macros > Sample Macro |
Top Previous Next |
|
To give you an idea of how a macro might look, here's a simple example: ' This sample macro goes through all the records in the currently opened database ' For any record for which the person is "John Smith" and the project is "Jupiter Database" ' the macro will change the rate to $85.00 per hour Sub Main Dim App As Object Set App = CreateObject("TimeLog.Application")
App.SetSQL("select start, person, project, rate, key from timerecords order by start") NumRecords = App.GetNumRecords() Dim Person As Variant Dim Project As Variant Dim NewRate As Variant
Dim ResultCode As Long Person = "" Project = "" NewRate = 85.00
For i=1 To NumRecords If i=1 Then App.MoveFirst() Else App.MoveNext() End If
Person = App.GetFieldValue(1, ResultCode) ' Field 0 = Start, Field 1=Person, Field 2=Project Project = App.GetFieldValue(2, ResultCode)
If Person = "John Smith" And Project="Jupiter Database" Then MsgBox("Changing the Rate...") App.SetFieldValue(3, NewRate) End If
Next i
App.RefreshDisplay() End Sub Visit the Responsive Software web site http://www.ResponsiveSoftware.com for additional examples. |