Hola Edgar,
Código vb:
Ver originalPublic Function getUnidad(Componente As String)
Dim RecordSet As New ADODB.RecordSet
Dim cn As New ADODB.Connection
Dim provStr As String
cn.Provider = "sqloledb"
provStr = "Server=MiServidor;Database=Midb;Trusted_Connection=no"
cn.Open provStr, "user", "pass123", 0
RecordSet.Open "SELECT item_no, item_desc_1, mfg_uom FROM imitmidx_sql WHERE item_no = '" & Componente & "'", cn, adOpenDynamic, adLockPessimistic
If RecordSet.BOF And RecordSet.EOF Then
MsgBox "No hay registros"
Else
getUnidad = RecordSet("mfg_uom")
End If
cn.Close
End Function
En las referencias de Visual Basic activa la referencia llamada Microsoft ActiveX Data Objects 2.1 Library.
Espero sea de ayuda, saludos.