Access - RECORRER 2 TABLAS

 
Vista:

RECORRER 2 TABLAS

Publicado por ROBERTO (145 intervenciones) el 06/11/2007 18:15:06
Mi consulta es la siguiente. Tengo 2 tablas una llamada [ARTICULOS] y otra [ARTICULOS CON CODIGO DE BARRAS].

Tengo que recorrer la Tabla de [ARTICULOS ACTUALIZADOS CON CODIGO DE BARRAS] e ir comparando con la Tabla de [ARTICULOS], a traves del campo [ARTICULO] y [ARTIC] respectivamente.
Si coinciden los Articulos tengo que añadir el valor de un campo de la tabla [ARTICULOS ACTUALIZADOS CON CODIGO DE BARRAS] a la tabla [ARTICULOS].

Esto es lo que yo he hecho pero que no me funciona correctamente.

Dim rst As DAO.Recordset
Dim dst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("SELECT * FROM [ARTICULOS ACTUALIZADOS CON CODIGO DE BARRAS]")
Set dst = CurrentDb.OpenRecordset("SELECT * FROM [ARTICULOS]")

rst.MoveLast
If rst.RecordCount = 0 Then
MsgBox ("No hay registros que modificar"), vbCritical
Exit Sub
End If

dst.MoveLast
If dst.RecordCount = 0 Then
MsgBox ("No hay registros que modificar"), vbCritical
Exit Sub
End If

rst.MoveFirst
dst.MoveFirst
BUSCARARTICULOS:
While Not rst.EOF
GoTo BUSCARENTRADAS
Wend
rst.Close
dst.Close
Set rst = Nothing
Set dst = Nothing
MsgBox ("Registros Modificados"), vbInformation
GoTo fin

BUSCARENTRADAS:
While Not dst.EOF
If dst![ARTIC] = rst![ARTICULO] Then
dst.Edit
If rst![CODBAR] > 0 Then
dst![DESCPG].Value = rst![NOMART].Value
dst![CB] = -1
dst.Update
Else
dst![DESCPG].Value = rst![NOMART].Value
dst.Update
End If
rst.MoveNext
GoTo BUSCARARTICULOS
Else
dst.MoveNext
End If
Wend
fin:

End Sub
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

RE:RECORRER 2 TABLAS

Publicado por mbellido (271 intervenciones) el 07/11/2007 10:12:27
creo que es mas facil hacerlo con una consulta de actualizacion de datos
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