Cargar un combo desde una db ( Visual basic )
Visual Basic 20 julio 2007
Con un recordset cargaremos un combo. Para ello tenemos que iterar el recordset y en cada elemento del recordset, añadiremos un item en el combo:
While Not Rs.EOF
frmPrincipal.Combo.AddItem Rs(“CampoBD”) & “;” & Rs(“CODIGO”)
Rs.MoveNext
Wend
Vota este artículo:
Posts anterior y posterior:
Posts Relacionados:
- Previo: « Colocar icono junto al reloj (Visual Basic).
- Siguiente: Web de recursos de Visual basic. »


julio 25th, 2007 a las 12:51 pm
Buen dia, la verdad que encontre gran informacion que me sirvio mucho, haber si me puedes ayudar. Tengo un formulario, en el cual tengo un combo y un text, y lo que quiero hacer es al desplegar el combo y seleccionar algun dato me lo relacione con el text, por favor si me puedes ayudar te lo agradecere.
Desde ya muchas gracias.
julio 25th, 2007 a las 1:11 pm
Hola Roby, no se realmente que es lo que quieres relacionar o mostrar en el text. Si lo que quieres es que el elemento activo del combo te lo ponga en en el text es muy simple.
Private Sub Combo1_Click()
Text1.Text = Combo1.Text
End Sub
agosto 13th, 2007 a las 2:05 pm
‘Assumes: All you need to do is make a new project. Add: 2 Command
Buttons, 1 ListBox, 1 TextBox
Private Sub Command1_Click()
Dim a As Long
Dim b As String
If Command1.Caption = “&Add Items” Then
For a = 1 To 200
List1.AddItem “Item #” & a
Next
Command1.Caption = “&Extract Em!”
Else
‘Why do we use b = b & List1.List(a) & v
‘ bCrLf
‘and not Text1.Text = Text1.Text & List1
‘ .List(a) & vbCrLf
‘because if you use it that way. It will
‘ make the text box flash
For a = 0 To (List1.ListCount – 1)
b = b & List1.List(a) & vbCrLf
Caption = “On Number: ” & a + 1
Next
Text1.Text = b
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim a As Long
Me.Width = 5775
Me.Height = 3420
Me.Left = (Screen.Width – Me.Width) / 2
Me.Top = (Screen.Height – Me.Height) / 2
MessWithControls ‘Check Sub
End Sub
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
Private Sub MessWithControls()
List1.Width = 2175
List1.Height = 2790
List1.Left = 120
List1.Top = 120
Text1.Width = 3135
Text1.Height = 2175
Text1.Left = 2400
Text1.Top = 120
Text1.Text = “”
Command1.Width = 1215
Command1.Height = 495
Command1.Left = 4320
Command1.Top = 2400
Command1.Caption = “&Add Items”
Command2.Width = 1215
Command2.Height = 495
Command2.Left = 2400
Command2.Top = 2400
Command2.Caption = “E&xit”
End Sub
junio 6th, 2008 a las 5:59 am
thanks you for the information.
septiembre 15th, 2010 a las 2:06 am
quiero saber como puedo mostrar todos los clientes en una de una base de datos en el combo.