Hola a todos... Alguien me podria decir que hice mal en la primera
consulta, falla en la linea donde señalo. La segunda hace lo mismo.
y funciona bien. Quiero aprender el metodo de la primera, que fue
posteado hace unos dias. Gracias.
Sub TraerNumeroFactura()
Dim Cnn As New ADODB.Connection
Dim Rst As New ADODB.Recordset
Dim strSQL As String
Dim Ruta As String
Ruta = ThisWorkbook.Path
With Cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & Ruta & "\Base.mdb"
.Open
End With
strSQL = "SELECT MAX(NFactura) FROM Ventas"
Rst.Open Source:=strSQL, ActiveConnection:=Cnn,
CursorType:=adOpenKeyset, LockType:=adLockOptimistic
Cells(3, 22).Value = Rst!NFactura '>>>>FALLA EN ESTA LINEA
Cnn.Close
Set Cnn = Nothing
Set Rst = Nothing
End Sub
Sub TraerNumeroFactura()
Dim Cnn As ADODB.Connection
Dim Rst As ADODB.Recordset
Dim Ruta As String
Ruta = ThisWorkbook.Path
Set Cnn = New ADODB.Connection
With Cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & Ruta & "\Base.mdb"
.Open
End With
Set Rst = New ADODB.Recordset
Rst.Open "SELECT MAX(NFactura) FROM Ventas", Cnn, , , adCmdText
Hoja1.Cells(3, 22).CopyFromRecordset Rst
Rst.Close: Set Rst = Nothing
Cnn.Close: Set Cnn = Nothing
End Sub
Leer las respuestas