Private Sub cbotienda_KeyPress(KeyAscii As Integer)
Dim cmd As String
Dim sql As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
If KeyAscii = 13 Then 'Si la tecla es INTRO entonces...
cmd = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\"Ruta de la BBDD".mdb;Persist Security Info=false"
Set cn = New ADODB.Connection
With cn
.ConnectionString = cmd
.Open
End With
sql = "SELECT * FROM DATOS WHERE TIENDA LIKE " & Me.cbotienda.Text & "%" 'Esto es para que busque la primera tienda que empieze por esos caracteres
Set rs = New ADODB.Recordset
With rs
.Open sql, cn, adOpenForwardOnly, adLockReadOnly
End With
If Not rs.EOF then
cbotienda.Text = rs![tienda]
txtnombre.Text = rs![nombre]
txtrouter.Text = rs![router]
txtservidor.Text = rs![servidor]
txttipo.Text = rs![tipo]
rs.Close
Else
cbotienda.Text = ""
txtnombre.Text = ""
txtrouter.Text = ""
txtservidor.Text = ""
txttipo.Text = ""
MsgBox "Esta tienda no existe"
End If
Set rs = Nothing
cn.Close
Set cn = Nothing
End If
End Sub