Introduction
This is an image of the Main Switchboard Screen, where a Reminder Ticker is actively scrolling a continuous stream of information. The Automotive Sales & Service Company manages vehicle service contracts with corporate customers for various durations, storing all related data in an MS Access database.
Each month, some of these contracts are due for renewal. The responsible staff must then contact the respective customers to confirm whether they wish to renew their maintenance contracts with the company.
The Reminder Ticker displays key details, such as the Customer Code, Vehicle Model, Chassis Number, Vehicle Description, and Expiry Date, with the latter appearing as the ticker scrolls into view.
The input data for the Reminder Ticker is retrieved from the Vehicle Maintenance Contract table using a query that filters records with expiry dates falling within the current month. For each contract, the Customer Code, Vehicle Model Number, Chassis Number, Vehicle Description, and Expiry Date are concatenated into a Variant variable (as a String variable may limit the length to 255 characters). This combined text is then displayed in the ticker using a Timer control.
The VBA Code
The VB code that does this trick is given below:
Option Compare Database Option Explicit 'Global Declaration Dim strTxt Private Sub Form_Open(Cancel As Integer) Dim db As Database, rst As Recordset Dim rstcount As Integer, currMonth As Integer, marqMonth On Error GoTo Form_Open_Err currMonth = Month(Date) ' Expiry_Marque is a parameter Table which holds ' the Start-Date & End-Date of Current Month and uses to pick 'the Contract Expiry Cases falls within this period. marqMonth = Month(DLookup("ExpDateTo", "Expiry_Marque")) If currMonth marqMonth Then ' when the month is changed the parameter table is ' updated with changed period. ' i.e. Start-Date and End-Date of the Current Month DoCmd.SetWarnings False DoCmd.OpenQuery "Expiry_Marque_Updt", acViewNormal DoCmd.SetWarnings True End If 'checks whether any contract expiry cases are there 'during the month. rstcount = dCount("*", "Expiry_MarqueQ") If Nz(rstcount, 0) = 0 Then strTxt = String(60, " ") & "*" NO CONTRACT EXPIRY CASES FOR " strTxt = strTxt & Format(Date, "mmmm yyyy") & " **" GoTo Form_Open_Exit End If ' builds the String strTxt with ticker data. Set db = CurrentDb Set rst = db.OpenRecordset("Expiry_MarqueQ", dbOpenDynaset) strTxt = String(60, " ") & "Expiry Cases:" Do While Not rst.EOF With rst strTxt = strTxt & " ** {" & rst.AbsolutePosition + 1 & "}. CUST: [" strTxt = strTxt & ![CUST_COD] & "] MODEL :[" & ![MODL_COD] strTxt = strTxt & "] CHAS :[" & ![CHASSIS] & "](" & ![DESC] strTxt = strTxt & ") EXP.: " & ![EXP_DATE] End With rst.MoveNext Loop rst.Close 'A Text Box on the Form is set with the Total Number 'of Contracts getting expired. Me![mVehl] = rstcount & " Vehicles." ' the Timer is invoked and the time to refresh ' the control is set with quarter of a ' second. This value may be modified. Me.TimerInterval = 250 Set rst = Nothing Set db = Nothing Form_Open_Exit: Exit Sub Form_Open_Err: MsgBox Err.Description, ,"Form_Open" Resume Form_Open_Exit End Sub Private Sub Form_Timer() Dim x On Error GoTo Form_Timer_Error x = Left(strTxt, 1) strTxt = Right(strTxt, Len(strTxt) - 1) strTxt = strTxt & x ' Create a Label with the Name lblmarq ' on your Form to scroll the values ' The value 200 used in the Left Function may be ' modified based on the length of the ' Label. Format the Label with a fixed width font ' like Courier New so that you can correctly determine ' how many characters can be displayed on the legth ' of the Label at one time and change the value accordingly. lblmarq.Caption = Left(strTxt, 200) Form_Timer_Exit: Exit Sub Form_Timer_Error: MsgBox Err.Description, , "Form_Timer_Error" Resume Form_Timer_Exit End Sub
Ticker Active/Inactive States
The code starts executing automatically when the form opens and continues to run until the form is closed.
When the form becomes inactive—such as when another form is opened over it—the ticker is automatically deactivated. After all, there's no point in keeping the program running when no one is watching. When the form becomes active again, the ticker resumes automatically. To add this behavior to the reminder ticker, copy and paste the following code into the form's module:
Private Sub Form_Deactivate() Me.TimerInterval = 0 End Sub Private Sub Form_Activate() Me.TimerInterval = 250 End Sub
Download
You can download a demo sample database from the download link given below:
