Martin Reid
mwp.reid at qub.ac.uk
Tue Jan 23 15:39:26 CST 2007
John have a read at this. I sent the full listing to you of list as I think it would get bounced here. I just lifted this of the web. Might be useful Martin ' =============================================== ' Your combobox form ' =============================================== On Error GoTo Err_Handler ' ===================================== ' Declare clsSelectData object variable ' ===================================== Dim objSelectData As clsSelectData On Error GoTo Err_Handler ' ===================================== ' Open connection and instantiate ' clsSelectData object ' ===================================== If OpenADOConnection(g_cnn) Then Set g_rst = New ADODB.Recordset If objSelectData Is Nothing Then Set objSelectData = New clsSelectData End If ' ===================================== ' Load global recordset object ' ===================================== Call objSelectData.GetRecordset(g_cnn, g_rst) ' ===================================== ' Disconnect global recordset object ' and close global connection ' ===================================== Call DisconnectADORecordset(g_rst, g_cnn) End If ' Configure combobox properties With cboRecordset .RowSourceType = "Value List" .BoundColumn = 1 .ColumnCount = 2 .ColumnWidths = "0;1in" End With ' Load combo box with recordset values. With g_rst .MoveFirst Do Until .EOF ' The semi-colon in the string indicates a column break. The ID ' field is your BouondColumn, the concatenated last/first names ' are displayed. You CAN'T use a comma or semi-colon in place of ' the dash. cboRecordset.AddItem !id & ";" & !LastName & " - " & !FirstName .MoveNext Loop End With ' Ensure first item in Value List is displayed. With cboRecordset .DefaultValue = .ItemData(0) End With ' ===================================== ' Close global recordset object ' ===================================== Call CloseADORecordset(g_rst) Set objSelectData = Nothing Exit_Here: On Error Resume Next Call CloseADORecordset(g_rst) Set objSelectData = Nothing Exit Sub Err_Handler: Dim strErrorMessage As String strErrorMessage = "An error has occured in " & _ Err.Source & "." & vbCrLf & vbCrLf strErrorMessage = strErrorMessage & "Error Number: " & Trim(Str(Err.Number)) & vbCrLf _ & "Error Description: " & Err.Description MsgBox Prompt:=strErrorMessage, _ Buttons:=vbCritical, _ Title:="Error Report" Resume Exit_Here End Sub