My query is:
on how to insert texts from a table in an excel file, to textboxes (vba form) using an sql query.
this is the code:
Private Sub cmdBuscar_Click()
On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1
Dim nCampos As Integer
Dim miSQL As String
Dim CodBusqueda As String
'Valida que campo de busqueda esté lleno
If txtBusqueda.Value = "" Then
MsgBox "Debe ingresar datos a buscar"
Else
CodBusqueda = txtBusqueda
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
MySQL = "SELECT * FROM [hoha1$] WHERE [001_CODIGO] = " & CodBusqueda
objConnection.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=C:\VDL\CM_20180315_JQM_V08.xlsx;" & _
"Extended Properties=""Excel 12.0;HDR=Yes;"";"
objRecordset.Open miSQL, objConnection, adOpenStatic, adLockOptimistic, adCmdText
End If
TextBox1 = objRecordset.Fields(0).Name
End Sub
I would appreciate your answer. Thank you ...