Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Public Sub FillEmployees()
On Error GoTo ErrorHandler
[color green]'Set Reference to Microsoft DAO 3.xx Library.[/color]
[color green] 'set variables[/color]
Dim rs As DAO.Recordset
Dim db As Database
Dim lstItem As ListItem
Dim strSQL As String
Set db = CurrentDb()
strSQL = "SELECT * FROM Employees"
Set rs = db.OpenRecordset(strSQL)
With Me.ListView1
[color green]'Set ListView style[/color]
.View = lvwReport
[color green] 'This is not supported by ListView 5[/color]
.GridLines = True
.FullRowSelect = True
[color green]'Clear Header and ListItems[/color]
.ListItems.Clear
.ColumnHeaders.Clear
End With
[color green] 'Set up column headers[/color]
With Me.ListView1.ColumnHeaders
.Add , , "Emp ID", 1000, lvwColumnLeft
.Add , , "Salutation", 700, lvwColumnLeft
.Add , , "Last Name", 2000, lvwColumnLeft
.Add , , "First Name", 2000, lvwColumnLeft
.Add , , "Hire Date", 1500, lvwColumnRight
End With
[color green] ' Add items and subitems to list control.[/color]
rs.MoveFirst
Do Until rs.EOF
Set lstItem = Me.ListView1.ListItems.Add()
lstItem.Text = rs!EmployeeID
lstItem.SubItems(1) = rs!TitleOfCourtesy
lstItem.SubItems(2) = rs!LastName
lstItem.SubItems(3) = rs!FirstName
lstItem.SubItems(4) = rs!HireDate
[color green]'Next row[/color]
rs.MoveNext
Loop
[color green] 'close recordset[/color]
rs.Close
DoCmd.Echo True
ErrorHandlerExit:
Exit Sub
ErrorHandler:
If Err = 3021 Then [color green] ' no current record[/color]
Resume Next
Else
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End If
End Sub
Private Sub Form_Load()
Call FillEmployees
End Sub
lstItem.SubItems(1) = rs!TitleOfCourtesy
lstItem.SubItems(2) = rs!LastName
lstItem.SubItems(1) = Nz(rs!TitleOfCourtesy, "N/A")
lstItem.SubItems(2) = Nz(Trim(rs!LastName))
[color green]'formatting date[/color]
lstItem.SubItems(4) = Format(rs!HireDate, "Medium Date")
lstItem.SubItems(4) = Format(rs!HireDate, "dd-mmm-YYYY")
[color green]'formatting currency[/color]
lstItem.SubItems(4) = Format(rs!SumOfFreight, "##,##0.00#")
lstItem.SubItems(2) = Format(rs!UnitPrice, "$#,##,0.00#")
[color green]'Percentage[/color]
lstItem.SubItems(4) = Format(rs!Discount, "#,##,0%")