Problema de conexion

Me aparece un error al tratar de obtener los datos donde legalizacion = a lo que tiene el label el dato de legalizacion es de tipo numerico.
Private Sub Command1_Click()
Set Rec3 = New ADODB.Recordset
    With Rec3
        Set .ActiveConnection = Con
        .CursorType = adOpenDynamic
        .CursorLocation = adUseClient
        .LockType = adLockOptimistic
        .Source = "select * from RECIBOS where LEGALIZACION = " & lblLegalizacionNo.Caption & ""
        .Open
    End With
    Set DataGrid1.DataSource = Rec
End Sub

1 Respuesta

Respuesta
1
¿Mensaje de error? ¿El del titulo? Donde le das Con. Open(¿)?
El error es
Error '-2147217913 (80040e07)' en tiempo de ejecucion:
No coinciden los tipos de datos en la expresion de criterios.
aparece en esta parte del codigo:
Private Sub Command1_Click()
Set Rec3 = New ADODB.Recordset
    With Rec3
        Set .ActiveConnection = Con
        .CursorType = adOpenDynamic
        .CursorLocation = adUseClient
        .LockType = adLockOptimistic
        .Source = "select * from RECIBOS where LEGALIZACION = '" & lblLegalizacionNo.Caption & "'"
        .Open
    End With
    Set DataGrid1.DataSource = Rec3
End Sub
Y este es el codigo completo:
Private Con As New Connection
Private Rec As ADODB.Recordset
Private Rec2 As ADODB.Recordset
Private Rec3 As ADODB.Recordset
Public var As String
Dim addFlag As Boolean
Private Sub cmdCancelar_Click()
If Rec.EOF Then
    Display
Else
    Display
    Rec.CancelUpdate
    'Rec2.CancelUpdate
    'Rec3.CancelUpdate
    Form_Activate
    cmdIngresar.Visible = False
    txtValorLegalizacion.Text = ""
    lblTotal2.Caption = ""
    Label1.Visible = False
    Label2.Visible = False
    txtConcepto.Text = ""
    txtConcepto.Visible = False
    txtValor.Text = ""
    txtValor.Visible = False
    cmdNuevo.Enabled = True
    If permiso = "A" Then cmdModificar.Enabled = True
    If permiso = "B" Then cmdModificar.Enabled = True
    cmdCancelar.Enabled = False
    cmdGuardar.Enabled = False
    cmdFirst.Enabled = True
    cmdPrevious.Enabled = True
    cmdNext.Enabled = True
    cmdLast.Enabled = True
End If
cmdIngresar.Visible = False
Label1.Visible = False
Label2.Visible = False
txtConcepto.Visible = False
txtValor.Visible = False
End Sub
Private Sub cmdFirst_Click()
Rec.MoveFirst
Display
End Sub
Private Sub cmdGuardar_Click()
Set Con = New ADODB.Connection
With Con
    .ConnectionString = "provider = microsoft.ace.oledb.12.0;data source=D:\PROYECTO TYT\TYT.accdb"
    .Open
End With
Dim strSql As String
For i = 1 To Me.DataGrid1.ApproxCount
    strSql = "insert into RECIBOS values('" + CStr(Me.DataGrid1.Columns(0).CellValue(i)) + "','" + Me.DataGrid1.Columns(1).CellValue(i) + "','" + Me.DataGrid1.Columns(2).CellValue(i) + "','" + CStr(Me.DataGrid1.Columns(3).CellValue(i)) + "')"
    Con.Execute strSql
Next
If lblTotal2.Caption = "" Then
    MsgBox "DEBE INGRESAR LOS DATOS Y VALORES"
    txtConcepto.SetFocus
Else
    With Rec2
        If addFlag Then .AddNew
        Rec2!LEGALIZACION = lblLegalizacionNo.Caption
        Rec2!USUARIO = lblNombre.Caption
        Rec2!ANTICIPODIRIGIDO = lblDirigdoA.Caption
        Rec2!VALORANTICIPO = lblValorAnticipo2.Caption
        Rec2!OBRA = lblObra2.Caption
        Rec2!VALORLEGALIZACION = txtValorLegalizacion.Text
        Rec2!TOTAL = lblTotal2.Caption
        .Update
    End With
    addFlag = False
    cmdNuevo.Enabled = True
    If permiso = "A" Then cmdModificar.Enabled = True
    If permiso = "B" Then cmdModificar.Enabled = True
    cmdGuardar.Enabled = False
    cmdCancelar.Enabled = False
    cmdFirst.Enabled = True
    cmdPrevious.Enabled = True
    cmdNext.Enabled = True
    cmdLast.Enabled = True
    'cmdBuscar.Enabled = True
    'cmdCancelarBuscar.Enabled = True
    cmdIngresar.Visible = False
    Label1.Visible = False
    Label2.Visible = False
    txtConcepto.Visible = False
    txtValor.Visible = False
End If
End Sub
Private Sub cmdIngresar_Click()
Rec3.AddNew
Rec3(0) = lblLegalizacionNo.Caption
Rec3(1) = lblObra2.Caption
Rec3(2) = txtConcepto.Text
Rec3(3) = txtValor.Text
Rec3.Update
Dim suma As Double
suma = 0
For i = 1 To Me.DataGrid1.ApproxCount
    suma = suma + Me.DataGrid1.Columns(3).CellValue(i)
Next
Me.txtValorLegalizacion.Text = FormatCurrency(suma)
Dim res As Long
Dim num1 As Long
Dim num2 As Long
num1 = FormatNumber(lblValorAnticipo2.Caption)
num2 = FormatNumber(txtValorLegalizacion.Text)
res = num1 - num2
lblTotal2.Caption = FormatCurrency(res)
txtConcepto.Text = ""
txtValor.Text = ""
End Sub
Private Sub cmdLast_Click()
Rec.MoveLast
Display
End Sub
Private Sub cmdModificar_Click()
cmdGuardar.Enabled = True
cmdCancelar.Enabled = True
End Sub
Private Sub cmdNext_Click()
With Rec
    .MoveNext
    If .EOF Then .MoveLast
End With
Display
End Sub
Private Sub cmdNuevo_Click()
addFlag = True
cmdNuevo.Enabled = False
cmdModificar.Enabled = False
cmdGuardar.Enabled = True
cmdCancelar.Enabled = True
cmdFirst.Enabled = False
cmdPrevious.Enabled = False
cmdNext.Enabled = False
cmdLast.Enabled = False
cmdIngresar.Visible = True
Label1.Visible = True
Label2.Visible = True
txtConcepto.Visible = True
txtValor.Visible = True
End Sub
Private Sub cmdPrevious_Click()
With Rec
    .MovePrevious
    If .BOF Then .MoveFirst
End With
Display
End Sub
Private Sub Command1_Click()
Set Rec3 = New ADODB.Recordset
    With Rec3
        Set .ActiveConnection = Con
        .CursorType = adOpenDynamic
        .CursorLocation = adUseClient
        .LockType = adLockOptimistic
        .Source = "select * from RECIBOS where LEGALIZACION = '" & lblLegalizacionNo.Caption & "'"
        .Open
    End With
    Set DataGrid1.DataSource = Rec3
End Sub
Private Sub Form_Activate()
Set Rec3 = New ADODB.Recordset
    With Rec3
        .Fields.Append "NO", adInteger, 20
        .Fields.Append "OBRA", adVarChar, 250
        .Fields.Append "CONCEPTO", adVarChar, 250, adFldUpdatable
        .Fields.Append "VALOR", adCurrency, adFldUpdatable
        .Open
    End With
Set Me.DataGrid1.DataSource = Rec3
Display
End Sub
Private Sub Form_Load()
Dim permiso As String
lblNombre = var
permiso = frmINGRESO.acc
If permiso = "A" Then
    cmdNuevo.Enabled = True
    cmdModificar.Enabled = True
    cmdCancelar.Enabled = True
    cmdGuardar.Enabled = True
    cmdBorrar.Enabled = True
ElseIf permiso = "B" Then
    cmdNuevo.Enabled = True
    cmdModificar.Enabled = True
    cmdCancelar.Enabled = True
    cmdGuardar.Enabled = True
    cmdBorrar.Enabled = False
Else
    cmdNuevo.Enabled = True
    cmdModificar.Enabled = False
    cmdCancelar.Enabled = True
    cmdGuardar.Enabled = True
    cmdBorrar.Enabled = False
End If
Set Con = New ADODB.Connection
With Con
    .ConnectionString = "provider = microsoft.ace.oledb.12.0;data source=D:\PROYECTO TYT\TYT.accdb"
    .Open
End With
Set Rec = New ADODB.Recordset
Rec.Open "ANTICIPOS", Con, adOpenDynamic, adLockOptimistic, adCmdTable
addFlag = False
Set Rec2 = New ADODB.Recordset
Rec2.Open "LEGALIZACIONES", Con, adOpenDynamic, adLockOptimistic, adCmdTable
addFlag = False
Set Rec3 = New ADODB.Recordset
Rec3.Open "RECIBOS", Con, adOpenDynamic, adLockOptimistic, adCmdTable
addFlag = False
cmdGuardar.Enabled = False
cmdCancelar.Enabled = False
cmdIngresar.Visible = False
Label1.Visible = False
Label2.Visible = False
txtConcepto.Visible = False
txtValor.Visible = False
End Sub
Private Sub Display()
If Rec.EOF Then
    MsgBox "NO EXISTEN REGISTROS"
    cmdNuevo_Click
Else
    lblLegalizacionNo.Caption = Rec!NO
    lblDirigdoA.Caption = Rec!ANTICIPODIRIGIDOA
    lblValorAnticipo2.Caption = FormatCurrency(Rec!VALORANTICIPO)
    lblObra2.Caption = Rec!OBRA
    'txtValorLegalizacion.Text = Rec!VALORLEGALIZACION
    'lblTotal2.Caption = Rec!TOTAL
    Set Con = New ADODB.Connection
    With Con
        .ConnectionString = "provider = microsoft.ace.oledb.12.0;data source=D:\PROYECTO TYT\TYT.accdb"
        .Open
    End With
End If
End Sub
Private Sub txtLegalizacionNo_Change()
Dim buscar As String
buscar = txtLegalizacionNo
Dim con2 As ADODB.Connection
If txtLegalizacionNo.Text = Empty Then
    MsgBox "SE REQUIERE NUMERO DE ANTICIPO"
    txtLegalizacionNo.SetFocus
End If
Set Con = New ADODB.Connection
With Con
    .ConnectionString = "provider = microsoft.ace.oledb.12.0;data source=D:\PROYECTO TYT\TYT.accdb"
    .Open
End With
Set Rec = New ADODB.Recordset
With Rec
    Set .ActiveConnection = Con
    .CursorType = adOpenDynamic
    .CursorLocation = adUseClient
    .LockType = adLockOptimistic
    .Source = "select * from PERMISOS where LEGALIZACION = '" & lblLegalizacionNo.Caption & "'"
    .Open
End With
If (Rec.EOF) Then
    MsgBox "EL REGISTRO NO EXISTE"
Else
    Display
End If
End Sub
Si el campo es numerico, no tienes por que colocarlo entre comillas simples como tienes en el codigo.
Ese creo es el problema

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas