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


0