Option Explicit
Private Sub cboCustomer_Change()
On Error GoTo Err_Handler
Dim strSql As String
Dim AdoCnn As ADODB.Connection, AdoRs As ADODB.Recordset
If IsNull(Me.cboCustomer.Value) Then Exit Sub
If Trim(CStr(Me.cboCustomer.Value)) = "" Then Exit Sub
'Get a connection to database
Set AdoCnn = GetDatabaseConnection()
If AdoCnn Is Nothing Then
Exit Sub
End If
AdoCnn.Open
strSql = "select [Project Name] from [tblProject] where [Customer
ID]=" & Me.cboCustomer.Value
'Instantiate ADODB Recordset object
Set AdoRs = New ADODB.Recordset
'Open Recordset
AdoRs.Open strSql, AdoCnn, adOpenForwardOnly, adLockOptimistic
Me.lstProjects.Clear
'Populate Projects listbox
Do While Not AdoRs.EOF
Me.lstProjects.AddItem AdoRs![Project Name]
AdoRs.MoveNext
Loop
'Close Recordset object
AdoRs.Close
'Close ADODB Connection Object
AdoCnn.Close
Set AdoRs = Nothing
Set AdoCnn = Nothing
Exit Sub
Err_Handler:
MsgBox Err.Description, vbInformation
End Sub
Private Sub cboCustomer_DropButtonClick()
On Error GoTo Err_Handler
Dim strSql As String
Dim AdoCnn As ADODB.Connection, AdoRs As ADODB.Recordset
'Check if customer dropdown is already populated
If Me.cboCustomer.ListCount > 0 Then Exit Sub
'Get a connection to database
Set AdoCnn = GetDatabaseConnection()
If AdoCnn Is Nothing Then
Exit Sub
End If
AdoCnn.Open
strSql = "select [Customer ID], [Cust Name] from [tblCustomer]
order by [Cust Name]"
'Instantiate the ADODB Recordset object
Set AdoRs = New ADODB.Recordset
'Open Recordset
AdoRs.Open strSql, AdoCnn, adOpenForwardOnly, adLockOptimistic
Me.cboCustomer.Clear
'Populate the first value (blank) of the Customer dropdown
Me.cboCustomer.AddItem "0"
Me.cboCustomer.Column(1, Me.cboCustomer.ListCount - 1) = ""
'Populate the Customer dropdown with the list of values form the
database table
Do While Not AdoRs.EOF
Me.cboCustomer.AddItem AdoRs![Customer ID]
Me.cboCustomer.Column(1, Me.cboCustomer.ListCount - 1) =
AdoRs![Cust Name]
AdoRs.MoveNext
Loop
'Close Recordset Object
AdoRs.Close
'Close the Connection object
AdoCnn.Close
Set AdoRs = Nothing
Set AdoCnn = Nothing
Exit Sub
Err_Handler:
MsgBox Err.Description, vbInformation
End Sub
Private Function GetDatabaseConnection() As ADODB.Connection
Dim dbPath As String
Dim AdoCnn As ADODB.Connection
Set GetDatabaseConnection = Nothing
On Error GoTo Err_Handler
dbPath = ActivePresentation.Path
If VBA.Right(VBA.Trim(dbPath), 1) <> "\" Then
dbPath = dbPath & "\"
End If
dbPath = dbPath & "CustomerSolutions.mdb"
Set AdoCnn = New ADODB.Connection
AdoCnn.Provider = "Microsoft.JET.OLEDB.4.0"
AdoCnn.Properties("Data Source") = dbPath
AdoCnn.Properties("Jet OLEDB

atabase Locking Mode") = 1
AdoCnn.CursorLocation = adUseServer
Set GetDatabaseConnection = AdoCnn
Exit Function
Err_Handler:
MsgBox Err.Description, vbInformation, "Get Database Connection"
End Function