devxlogo

Show Data With Outlook Grid

Show Data With Outlook Grid

You can easily create a calendar grid similar to the one in Outlook to show data. First, start a VB project, then place an MSFlex Grid on the form, with two textboxes to set the start and end dates and a command button to populate the grid. Paste this code in the Form1 code pane:

  Private Sub Command1_Click()     Dim ldBegDate As Date     Dim ldEndDate As Date     Dim lsMonth As String     Dim li, lsStr, lsStartDate, _          lsEndDate, liStartRow, _          liEndRow, liCnt, lsDate, liX     ldBegDate = Format(Text1, _          "mm/dd/yyyy")     ldEndDate = Format(Text2, _          "mm/dd/yyyy")     MSFlexGrid1.Clear: _          MSFlexGrid1.Cols = 5: _          MSFlexGrid1.Rows = 1: _          MSFlexGrid1.RowHeightMin _          = 800     For li = 0 To DateDiff("M", _          ldBegDate, ldEndDate)          lsMonth = Format(DateAdd("m", _               li, ldBegDate), "mmmyyyy")          '== check what month is being           '== processed          lsStartDate = "": lsEndDate = ""          '== Starting Month          If InStr(1, lsMonth, _               Format(ldBegDate, _               "mmmyyyy")) _               Then lsStartDate = ldBegDate          '== Ending Month          If InStr(1, lsMonth, _               Format(ldEndDate, _               "mmmyyyy")) _               Then lsEndDate = ldEndDate          '== Neither Starting or Ending           '== Month          If lsStartDate = "" Then _               lsStartDate = _               Format(DateAdd("m", li, _               ldBegDate), "mm/01/yyyy")          If lsEndDate = "" Then _               lsEndDate = _               Format(DateAdd("m", 1, _               Format(lsStartDate, _               "mm/01/yyyy")) - 1, _               "mm/dd/yyyy")          liStartRow = MSFlexGrid1.Rows          liEndRow = liStartRow + _               DateDiff("d", lsStartDate, _               lsEndDate)          MSFlexGrid1.Rows = _               MSFlexGrid1.Rows + _               liEndRow - liStartRow + 1          MSFlexGrid1.Col = 0          '== Put Dates in grid          For liCnt = 0 To DateDiff("d", _               lsStartDate, lsEndDate)               lsDate = DateAdd("d", liCnt, _                    lsStartDate)               MSFlexGrid1.Row = liStartRow _                    + liCnt               MSFlexGrid1.Text = lsDate               MSFlexGrid1.CellFontSize = _                    10: _                    MSFlexGrid1.CellFontBold _                    = True               MSFlexGrid1.CellAlignment = _                    flexAlignCenterCenter               If WeekDay(lsDate, vbMonday) _                    > 5 Then                    For liX = 1 To _                         MSFlexGrid1.Cols - 1                         MSFlexGrid1.Col = liX                         MSFlexGrid1.CellBackColor = _          &HC0C0C0:   _          MSFlexGrid1.CellForeColor _          = &H80000015                    Next                    MSFlexGrid1.Col = 0               End If          Next     Next '== li..Start to End DateEnd Sub
See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist