Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.
Private Sub UserForm_Initialize() On Error GoTo UserForm_Initialize_Err Dim cnn As New ADODB.Connection Dim rst As New ADODB.Recordset cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=C:\Databases\StaffDatabase.mdb" rst.Open "SELECT DISTINCT [Department] FROM tblStaff ORDER BY [Department];", _ cnn, adOpenStatic rst.MoveFirst With Me.ComboBox1 .Clear Do .AddItem rst![Department] rst.MoveNext Loop Until rst.EOF End With UserForm_Initialize_Exit: On Error Resume Next rst.Close cnn.Close Set rst = Nothing Set cnn = Nothing Exit Sub UserForm_Initialize_Err: MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!" Resume UserForm_Initialize_Exit End Sub