Visual Basic - Error 13 en tiempo de ejecución - no coinciden los tipos.

Life is soft - evento anual de software empresarial
 
Vista:

Error 13 en tiempo de ejecución - no coinciden los tipos.

Publicado por Seba (5 intervenciones) el 14/08/2017 17:27:45
Tengo este código que me tira ese error (el 13...) y no sé que estoy haciendo mal.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Private Sub Comando72_Click()
Dim FiltroCarrera As String
FiltroCarrera = "Carrera = '" & Me.Cuadro_combinado61 & "'"
If Me.Cuadro_combinado61 = "" Then
FiltroCarrera = "Carrera <> '""'"
End If
'Modalidad
Dim FiltroModalidad As String
FiltroModalidad = "Modalidad = '" & Me.Cuadro_combinado68 & "'"
If Me.Cuadro_combinado68 = "" Then
FiltroModalidad = "Modalidad <> '""'"
End If
'Turno
Dim FiltroTurno As String
FiltroTurno = "Turno = '" & Me.Cuadro_combinado70 & "'"
If Me.Cuadro_combinado70 = "" Then
FiltroTurno = "Turno <> '""'"
End If
'Año
Dim FiltroAño As String
FiltroAño = "Año = '" & Me.Cuadro_combinado87 & "'"
If Me.Cuadro_combinado87 = "" Then
FiltroAño = "Año <> '""'"
End If
'AC
Dim FiltroAC As String
FiltroAC = "AC = " & Me.Cuadro_combinado119 & ""
If Me.Cuadro_combinado119 = "" Then
FiltroAC = "AC <> '""'"
End If
'Activo
Dim FiltroActivo As String
FiltroActivo = "Activo = " & Me.Verificación107 & ""
Dim FiltroTotal As String
FiltroTotal = FiltroCarrera And FiltroModalidad And FiltroTurno And FiltroAño And FiltroAC And FiltroAtivo
Me.Filter = FiltroTotal
Me.FilterOn = True
End Sub

El error me lo tira en la antepenúltima fila: FiltroTotal = FiltroCarrera And FiltroModalidad And FiltroTurno And FiltroAño And FiltroAC And FiltroAtiv
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Andres Leonardo
Val: 3.117
Oro
Ha mantenido su posición en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

Error 13 en tiempo de ejecución - no coinciden los tipos.

Publicado por Andres Leonardo (1798 intervenciones) el 14/08/2017 22:29:06
Pregunta son cadenas de caracteres???


si es asi Intenta asi


1
FiltroTotal = FiltroCarrera & FiltroModalidad & FiltroTurno & FiltroAño & FiltroAC & FiltroAtivo

si es que es texto... el and no tiene nada que ver en concatenacion de Strings
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Error 13 en tiempo de ejecución - no coinciden los tipos.

Publicado por Seba (5 intervenciones) el 16/08/2017 18:46:40
Andrés, gracias por tu respuesta me sirvió. Sin embargo, ahora me surge un nuevo problema, creo yo, más fácil de resolver.
El error que me tira ahora es el 3075 - error de sintaxis (falta operador):

Error de sintaxis (falta operador) en la expresión de consulta 'Carrera = "Modalidad = "Turno = "Año = "AC = '.

Ese mensaje me salta cuando dejo los filtros de búsqueda vacío.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Error 13 en tiempo de ejecución - no coinciden los tipos.

Publicado por Alejandro (1 intervención) el 12/01/2018 15:30:23
En mi caso el error aparece al validar el proyecto antes ejecutarlo; tengo una base Access, en la cual debo cargar unos archivos de texto, para ello desde un formulario ingreso el directorio donde se encuentran dichos archivos, como el directorio cambia mes a mes, debo mantener el cambio del directorio desde el formulario (que tiene asociada una tabla, donde se almacena el directorio).

Este mismo formato lo utilizo en otra base de datos, que carga todos los archivos que existen en un directorio, y también tengo que ingresar en un formulario dicho distrito. Lo que hice fue pasar, la Tabla donde se encuentra el directorio y módulo donde valida el directorio.

Está claro que tanto la variable donde debería quedar el path del directorio como el dato que se obtiene ambos son texto, por eso estoy confundido y no sé porque aborta.

El primer código es el proveniente de la base, donde funciona el módulo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
Public Function Existe_Dir(Path)
 
On Error GoTo Existe_Dir_Err
 
    If Not Dir(Path, vbDirectory) = vbNullString And Path <> "" Then
        Existe_Dir = True
    Else
        Existe_Dir = False
    End If
 
Existe_Dir_Exit:
    Exit Function
 
Existe_Dir_Err:
    Existe_Dir = False
    Resume Existe_Dir_Exit
 
End Function
 
Public Function SeleccionarDirectorio()
    'definimos las variables que emplearemos
    Dim Titulo, Directorio As String
    Titulo = "Selecciona la ruta de tu carpeta"
    On Error Resume Next
    'evitaría un error en caso de no seleccionar nada o pulsar ESC
    With CreateObject("shell.application")
        Directorio = .browseforfolder(0, Titulo, 0).Items.Item.Path
    End With: On Error GoTo 0
    'la siguiente instruccíon IF ejecuta una acción a modo de ejemplo
    If Directorio = "" Then
        MsgBox "No has marcado ningún directorio.", , "Operación no válida"
        SeleccionarDirectorio = ""
    Else
        'MsgBox "Ha seleccionado la siguiente ruta " & Directorio
        SeleccionarDirectorio = Directorio
    End If
End Function
 
 
Public Function Lee_DataDir()
 
    'Db será una base de datos:
    Dim Db As Database 'Variable para las Bases de Datos
    'Set Db = OpenDatabase("Nombre_Base_Datos")
    Set Db = CurrentDb
 
    Dim SQLTmp As String
    Dim MySnap As Recordset
 
    'SQLTmp = "select * from " & Nombre_Tabla & " <Consulta> " & " order by " & Clasificar
    SQLTmp = "Reco_Dir"
    Lee_DataDir = Null
 
    'Set MySnap = Db.OpenRecordset(SQLTmp, dbOpenSnapshot)
    Set MySnap = Db.OpenRecordset(SQLTmp, dbOpenSnapshot)
    Err = 0
    MySnap.MoveFirst
    If Err Then
        Err = 0
        'no hay datos, avisar
        MsgBox "No hay datos almacenados de directorio", , "Directorios"
        Exit Function
    End If
 
 
    MySnap.MoveFirst
    Do Until MySnap.EOF
            Lee_DataDir = MySnap!Directorio
            'Debug.Print MySnap!Directorio
            MySnap.MoveNext
    Loop
    MySnap.Close
 
End Function
 
 
 
Sub Graba_DataDir(Data_Directorio)
 
    'Db será una base de datos:
    Dim Db As Database 'Variable para las Bases de Datos
    'Set Db = OpenDatabase("Nombre_Base_Datos")
    Set Db = CurrentDb
 
    Dim SQLTmp As String
    Dim MySnap As Recordset
 
    SQLTmp = "Reco_Dir"
    'Lee_DataDir = Null
 
    Set MySnap = Db.OpenRecordset(SQLTmp) ', dbOpenSnapshot)
    Err = 0
    MySnap.MoveFirst
    If Err Then
        Err = 0
        'no hay datos, avisar
        MsgBox "Existe un Error", , "Directorios"
        Exit Sub
    End If
 
    'Añadir el resultado a un List
    'List1.Clear
 
    MySnap.MoveFirst
    MySnap.Edit
    MySnap!Directorio = Data_Directorio
    MySnap.Update
    MySnap.Close
 
End Sub
 
'------------------------------------------------------------
' MIGRACION
'
'------------------------------------------------------------
Public Function MIGRACION()
 
'On Error GoTo MIGRACION_Err
On Error Resume Next
Dim D As String
D = Lee_DataDir
 
 
    ' Suspende la emisión de avisos de proceso
    DoCmd.SetWarnings False
    'MsgBox "Directorio de Origen: " & Reco_Dir
 
    Set fs = Application.FileSearch
With fs
    .LookIn = D
    .SearchSubFolders = False
    .FileName = "GCR02_201*"
    If .Execute(SortBy:=msoSortbyFileName, _
    SortOrder:=msoSortOrderAscending) > 0 Then
 
        'Informa la cantidad de registros encontrados
 
        MsgBox "Se encontraron " & .FoundFiles.Count & _
            " archivo/s"
        For i = 1 To .FoundFiles.Count
 
            'Importa el archivo de texto directamente a la tabla "Cobros"
            DoCmd.TransferText acImportDelim, "cobros_delimitado", "COBROS", .FoundFiles(i)
            DoCmd.OpenQuery "Borra fechas"
            DoCmd.TransferText acImportDelim, "FP", "FPC", .FoundFiles(i)
            DoCmd.OpenQuery "Guarda fechas"
            'DoCmd.RunMacro "Cuenta las fechas"
 
            'Borra los archivos de error de importación
            Nombre1 = Right(Trim$(.FoundFiles(i)), 19)
            Nombre2 = Right(Left(Trim$(Nombre1), 15), 14)
            'ErroresDeImportación = Left(Trim$(Nombre1), 15) + "_ErroresDeImportación"
            'ErroresDeImportación = Nombre2 + "_ErroresDeImportación" (antes de la actualizacion)
            ErroresDeImportación = Nombre2 + "_ImportErrors"
            'DoCmd.DeleteObject acTable, ErroresDeImportación (antes de la actualizacion)
            DoCmd.DeleteObject acTable, ErroresDeImportación
        Next i
    Else
        MsgBox "No se encontraron archivos."
    End If
    'Corre macro que actualiza las tablas necesarias
    DoCmd.RunMacro "Para correr diariamente"
    DoCmd.DeleteObject acTable, "Errores al guardar Autocorrección de nombres"
End With
 
    MsgBox "Fin de la Carga. Comience la actualización de las tablas dinámicas"
    DoCmd.SetWarnings True
 
 
MIGRACION_Exit:
    Exit Function
 
MIGRACION_Err:
    MsgBox Error$
    Resume MIGRACION_Exit
MsgBox "Compactar"
End Function


Acá agrego el listado donde dá error el proyecto:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
Public Function Existe_Dir(Path)
 
On Error GoTo Existe_Dir_Err
 
    If Not Dir(Path, vbDirectory) = vbNullString And Path <> "" Then
        Existe_Dir = True
    Else
        Existe_Dir = False
    End If
 
Existe_Dir_Exit:
    Exit Function
 
Existe_Dir_Err:
    Existe_Dir = False
    Resume Existe_Dir_Exit
 
End Function
 
Public Function SeleccionarDirectorio()
    'definimos las variables que emplearemos
    Dim Titulo, Directorio As String
    Titulo = "Selecciona la ruta de tu carpeta"
    On Error Resume Next
    'evitaría un error en caso de no seleccionar nada o pulsar ESC
    With CreateObject("shell.application")
        Directorio = .browseforfolder(0, Titulo, 0).Items.Item.Path
    End With: On Error GoTo 0
    'la siguiente instruccíon IF ejecuta una acción a modo de ejemplo
    If Directorio = "" Then
        MsgBox "No has marcado ningún directorio.", , "Operación no válida"
        SeleccionarDirectorio = ""
    Else
        'MsgBox "Ha seleccionado la siguiente ruta " & Directorio
        SeleccionarDirectorio = Directorio
    End If
End Function
 
 
Public Function Lee_DataDir()
 
    'Db será una base de datos:
    Dim Db As Database 'Variable para las Bases de Datos
    'Set Db = OpenDatabase("Nombre_Base_Datos")
    Set Db = CurrentDb
 
    Dim SQLTmp As String
    Dim MySnap As Recordset
 
    'SQLTmp = "select * from " & Nombre_Tabla & " <Consulta> " & " order by " & Clasificar
    SQLTmp = "Reco_Dir"
    Lee_DataDir = Null
 
    'Set MySnap = Db.OpenRecordset(SQLTmp, dbOpenSnapshot)
    Set MySnap = Db.OpenRecordset(SQLTmp, dbOpenSnapshot) "En esta línea da Error 13 en tiempo de ejecución"
    Err = 0
    MySnap.MoveFirst
    If Err Then
        Err = 0
        'no hay datos, avisar
        MsgBox "No hay datos almacenados de directorio", , "Directorios"
        Exit Function
    End If
 
 
    MySnap.MoveFirst
    Do Until MySnap.EOF
            Lee_DataDir = MySnap!Directorio
            'Debug.Print MySnap!Directorio
            MySnap.MoveNext
    Loop
    MySnap.Close
 
End Function
 
 
 
Sub Graba_DataDir(Data_Directorio)
 
    'Db será una base de datos:
    Dim Db As Database 'Variable para las Bases de Datos
    'Set Db = OpenDatabase("Nombre_Base_Datos")
    Set Db = CurrentDb
 
    Dim SQLTmp As String
    Dim MySnap As Recordset
 
    SQLTmp = "Reco_Dir"
    'Lee_DataDir = Null
 
    Set MySnap = Db.OpenRecordset(SQLTmp) ', dbOpenSnapshot)
    Err = 0
    MySnap.MoveFirst
    If Err Then
        Err = 0
        'no hay datos, avisar
        MsgBox "Existe un Error", , "Directorios"
        Exit Sub
    End If
 
    'Añadir el resultado a un List
    'List1.Clear
 
    MySnap.MoveFirst
    MySnap.Edit
    MySnap!Directorio = Data_Directorio
    MySnap.Update
    MySnap.Close
 
End Sub
 
 
acá agrego el módulo desde donde llamo a la función:
 
Private Sub Importar_Click()
On Error GoTo Err_Importar_Click
 
    Dim DirectorioFuente As String
    Dim stDocName As String
    Dim nombrearchivo As String
    Dim MiArchivo, MiRuta, MiNombre
    Dim D As String
    D = Lee_DataDir
 
 DirectorioFuente = D
 
    DoCmd.SetWarnings False
    DoCmd.RunMacro "01-Borra-las-Tablas-Actuales"
    'stDocName = "02 Importa Archivos"
    'DoCmd.RunMacro stDocName
    'Ruta del DirectorioFuente
    'DirectorioFuente = "F:\Informes SAP\201712\Val 10\Operandos\" "Este sería el directorio desde donde obtendría los datos"
    ChDir DirectorioFuente
    MiRuta = CurDir
 
    'Nombre del archivo
    nombrearchivo = "_29_12_17"
 
    'Destino
    MiArchivoB = "Destino" & nombrearchivo & ".txt"
    'MsgBox MiArchivoB & " que recién armé"
        MiArchivo = Dir(MiArchivoB)
        'MsgBox MiArchivo & " que voy a validar"
        If MiArchivo = "Destino" & nombrearchivo & ".txt" Then
            DoCmd.TransferText acImportDelim, "Destino", "Destino", DirectorioFuente & "Destino" & nombrearchivo & ".txt"
            'DoCmd.CopyObject , "Destino", acTable, "Destino" & nombrearchivo & ""
            DoCmd.CopyObject , "Destino" & nombrearchivo, acTable, "Destino"
        Else
             'MsgBox "No hay archivo de Operandos"
        End If
 
    'Expediente
    MiArchivoB = "Expediente" & nombrearchivo & ".txt"
    'MsgBox MiArchivoB & " que recién armé"
        MiArchivo = Dir(MiArchivoB)
        'MsgBox MiArchivo & " que voy a validar"
        If MiArchivo = "Expediente" & nombrearchivo & ".txt" Then
            DoCmd.TransferText acImportDelim, "Expediente", "Expediente", DirectorioFuente & "Expediente" & nombrearchivo & ".txt"
            DoCmd.CopyObject , "Expediente" & nombrearchivo, acTable, "Expediente"
        Else
             'MsgBox "No hay archivo de Operandos"
        End If
 
    'Movein
    MiArchivoB = "Movein" & nombrearchivo & ".txt"
    'MsgBox MiArchivoB & " que recién armé"
        MiArchivo = Dir(MiArchivoB)
        'MsgBox MiArchivo & " que voy a validar"
        If MiArchivo = "Movein" & nombrearchivo & ".txt" Then
            DoCmd.TransferText acImportDelim, "Move-in_Move-out", "Movein", DirectorioFuente & "Movein" & nombrearchivo & ".txt"
            DoCmd.CopyObject , "Movein" & nombrearchivo, acTable, "Movein"
        Else
             'MsgBox "No hay archivo de Operandos"
        End If
 
    'Moveout
     MiArchivoB = "Moveout" & nombrearchivo & ".txt"
    'MsgBox MiArchivoB & " que recién armé"
        MiArchivo = Dir(MiArchivoB)
        'MsgBox MiArchivo & " que voy a validar"
        If MiArchivo = "Moveout" & nombrearchivo & ".txt" Then
            DoCmd.TransferText acImportDelim, "Move-in_Move-out", "Moveout", DirectorioFuente & "Moveout" & nombrearchivo & ".txt"
            DoCmd.CopyObject , "Moveout" & nombrearchivo, acTable, "Moveout"
        Else
             'MsgBox "No hay archivo de Operandos"
        End If
 
    'Operandos
    MiArchivoB = "Operando" & nombrearchivo & ".txt"
        'MsgBox MiArchivoB & " que recién armé"
        MiArchivo = Dir(MiArchivoB)
        'MsgBox MiArchivo & " que voy a validar"
        If MiArchivo = "Operando" & nombrearchivo & ".txt" Then
             DoCmd.TransferText acImportDelim, "Operandos", "Operando", DirectorioFuente & "Operando" & nombrearchivo & ".txt"
             DoCmd.CopyObject , "Operando" & nombrearchivo, acTable, "Operando"
        Else
             'MsgBox "No hay archivo de Operandos"
        End If
 
    'Suministro
     MiArchivoB = "Suministro" & nombrearchivo & ".txt"
        'MsgBox MiArchivoB & " que recién armé"
        MiArchivo = Dir(MiArchivoB)
        'MsgBox MiArchivo & " que voy a validar"
        If MiArchivo = "Suministro" & nombrearchivo & ".txt" Then
            DoCmd.TransferText acImportDelim, "Suministro", "Suministro", DirectorioFuente & "Suministro" & nombrearchivo & ".txt"
            DoCmd.CopyObject , "Suministro" & nombrearchivo, acTable, "Suministro"
        Else
             'MsgBox "No hay archivo de Operandos"
        End If
 
    'UnidadLectura
    MiArchivoB = "Unlec" & nombrearchivo & ".txt"
        MiArchivo = Dir(MiArchivoB)
        If MiArchivo = "Unlec" & nombrearchivo & ".txt" Then
            DoCmd.TransferText acImportDelim, "UnidadLectura", "Unlec", DirectorioFuente & "unlec" & nombrearchivo & ".txt"
            DoCmd.CopyObject , "unlec" & nombrearchivo, acTable, "unlec"
        Else
 
        End If
 
    'Divergentes
    MiArchivoB = "Divergente" & nombrearchivo & ".txt"
        'MsgBox MiArchivoB & " que recién armé"
        MiArchivo = Dir(MiArchivoB)
        'MsgBox MiArchivo & " que voy a validar"
        If MiArchivo = "Divergente" & nombrearchivo & ".txt" Then
            DoCmd.TransferText acImportDelim, "Divergentes", "Divergente", DirectorioFuente & "Divergente" & nombrearchivo & ".txt"
            DoCmd.CopyObject , "Divergente" & nombrearchivo, acTable, "Divergente"
            'MsgBox MiArchivo & " Está"
        Else
            'MsgBox "No hay archivo de Divergentes"
        End If
 
    DoCmd.RunMacro "Cerrar-lista-instal-exped"
    DoCmd.SetWarnings True
Exit_Importar_Click:
    Exit Sub
 
Err_Importar_Click:
    MsgBox Err.Description
    Resume Exit_Importar_Click
 
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 6
Ha aumentado su posición en 2 puestos en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

Error 13 en tiempo de ejecución - no coinciden los tipos.

Publicado por JOSE LUIS (3 intervenciones) el 31/01/2018 15:54:37
BUENAS TARDES

EL SISTEMA ME INDICA EL MISMO ERROR 13 NO COINCIDEN LOS TIPOS Y LA SINTAXIS QUE TENGO ES LA SIGUIENTE

While Mid(Form1.Text1.Text, CENTRAL, 12) <> ""
V_CENTRAL = Mid(Form1.Text1.Text, CENTRAL, 12)

ME PUEDEN AYUDAR
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 109
Ha aumentado 1 puesto en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

Error 13 en tiempo de ejecución - no coinciden los tipos.

Publicado por Yamil Bracho (226 intervenciones) el 31/01/2018 16:17:16
Como esta declarada la variable V_CENTRAL ?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar