Visual Basic para Aplicaciones - ComboBox con base datos access

Life is soft - evento anual de software empresarial
 
Vista:

ComboBox con base datos access

Publicado por Maclay (1 intervención) el 07/01/2022 03:42:04
Tengo un ComboBox2 de excel, que usa una tabla access, lo que quiero es poder combinar varios datos en ese comboBox para que se visualice, dicho ComboBox tiene otros asociados a el. se me puede ayudar lo agradezco, gracias.

Sub Actualizar()

If ComboBox2.Value <> "" Then
Dim Conn As ADODB.Connection
Dim MiConexion
Dim Rs As ADODB.Recordset
Dim MiBase As String
Dim query As String

MiBase = Hoja4.Range("D2").Value

Set Conn = New ADODB.Connection
MiConexion = MiBase

With Conn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Open MiConexion
End With

query = "SELECT * FROM Kanbas WHERE Código = " & ComboBox2.Value

Set Rs = New ADODB.Recordset
Rs.CursorLocation = adUseServer
Rs.Open source:=query, _
ActiveConnection:=Conn

With Rs
TextBox7.Text = .Fields("Estado")
If Not TextBox7.Text = "Asignada" Then

TextBox6.Text = .Fields("Fecha de inicio")
End If

End With

Rs.Close
Conn.Close
Set Rs = Nothing
Set Conn = Nothing

End If


CommandButton1.Enabled = False
CommandButton2.Enabled = False
CommandButton3.Enabled = False
CommandButton4.Enabled = False

If TextBox7.Text = "Asignada" Then
CommandButton1.Enabled = True

End If
If TextBox7.Text = "Ejecutando" Then

CommandButton2.Enabled = True
CommandButton3.Enabled = True

End If

If TextBox7.Text = "Pausada" Then

CommandButton4.Enabled = True

End If

End Sub
----------------------------------------------------------------------------------------------------------------------------------------------

Private Sub ComboBox2_Change()
If ComboBox2.Value = "" Then

Else
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""

Dim Conn As ADODB.Connection
Dim MiConexion
Dim Rs As ADODB.Recordset
Dim MiBase As String
Dim query As String

MiBase = Hoja4.Range("D2").Value

Set Conn = New ADODB.Connection
MiConexion = MiBase

With Conn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Open MiConexion
End With

query = "SELECT * FROM Kanbas WHERE Código=" & ComboBox2.Value & ";"


Set Rs = New ADODB.Recordset
Rs.CursorLocation = adUseServer
Rs.Open source:=query, _
ActiveConnection:=Conn

With Rs
TextBox1.Text = .Fields("Cliente")
TextBox2.Text = .Fields("Proyecto")
TextBox3.Text = .Fields("Tarea")
TextBox5.Text = .Fields("Nivel de prioridad")
TextBox4.Text = .Fields("Fecha limite")
TextBox7.Text = .Fields("Estado")
If TextBox7.Text <> "Asignada" Then
TextBox6.Text = .Fields("Fecha de inicio")
End If


End With


Rs.Close
Conn.Close
Set Rs = Nothing
Set Conn = Nothing



Call Actualizar

End If

End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder