"Move Next" function doesnt work! (1 Viewer)

Andreita_IEA

New member
Local time
Today, 05:20
Joined
Nov 4, 2013
Messages
3
Good evening.
Im trying to compare two tables (Sap table and Operational_Technical table)
Both has the following fields:
Sap Table:
SAP_Aircraft
SAP_DMI_Number

and the Operational_Technical table has:
MatriculaReal
DMI_Number

What Im trying to do is compare the fields "SAP_Aircraft" and "MatriculaReal" and if the program finds any difference shows a message telling me that.

This is the code Im using: (But it seems like the "Move next" doesnt move from the next "Matricula") It does make sense?


Private Sub Form_Load()
txtUser.Value = Gbl_Nombre
DoCmd.Maximize


Dim rsT As Recordset 'Recordset from Operational_Technical table
Dim rsS As Recordset 'Recordset from Sap Table
Dim txtSql As String
Dim SapMatricula As String
Dim AccessMatricula As String

Set rsS = CurrentDb.OpenRecordset("SAP", dbOpenDynaset)
Set rsT = CurrentDb.OpenRecordset("Operational_Technical", dbOpenDynaset)
SapMatricula = SapMatricula & rsS.Fields("SAP_Aircraft").Value
AccessMatricula = AccessMatricula & rsT.Fields("MatriculaReal").Value


Do While Not rsS.EOF Or rsT.EOF

If (SapMatricula = AccessMatricula) Then
MsgBox "Differences not found"
Else
MsgBox "Differences found"
End If
rsS.MoveNext
MsgBox "The currently registration is " & SapMatricula
Loop
rsS.Close
MsgBox "End"
End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:20
Joined
Aug 30, 2003
Messages
36,125
Your variables are set before the loop begins, so their value never changes.
 

Andreita_IEA

New member
Local time
Today, 05:20
Joined
Nov 4, 2013
Messages
3
Paul you were aboslutely right. I put the variables after the "Do While.." and it works!!..
Thank you so much. :)
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:20
Joined
Aug 30, 2003
Messages
36,125
Happy to help, and welcome to the site by the way!
 

Andreita_IEA

New member
Local time
Today, 05:20
Joined
Nov 4, 2013
Messages
3
Paul its me again.

Well, at this time the recordset its working. However what I wanna do now its to compare the fields from this two different tables (SAP table and Operational_Technical table) and if the program finds a difference between those two, then will add those values to another table, called "Diferencias".
At the end of the cycle I will show a message (which is a form instead of a msgbox), advising "Differences was found, would you like to open the list?", then if the user clicks "Yes" the table with all the differences found will be opened (Diferencias table). Its that make sense?

So, the issues that I currently have are:

1.Once I run the programm it asks me for the mat1 value. Doenst add it automatically to the "Diferencias" table
2. I dont know how to detect the fields where the differences exists, (i.e. SAP_Issue_Date/IssueDate or SAP_Cat/Cat and so on)
in order to change its color once I create the txt field on a form.
3.How can I create a conditional that detects into the "Diferencias" table, if the field mat1 its different than null.
4.I cant find the way to send back the current form and send to the front the Changes form

If you take a look of the code I just copied, you will find, as a comment, this issues. So you can understand where is exactly the part where the issue is presented.
Here I go:

Private Sub Form_Load()
txtUser.Value = Gbl_Nombre
DoCmd.Maximize

Dim rsT As Recordset 'Recordset from Operational_Technical table
Dim rsS As Recordset 'Recordset from Sap Table
Dim Mat1 As String 'Variable for the matricula field from SAP table
Dim Mat2 As String 'Variable for the Matricula field from Operational_Technical table

Set rsS = CurrentDb.OpenRecordset("SAP", dbOpenDynaset)
Set rsT = CurrentDb.OpenRecordset("Operational_Technical", dbOpenDynaset)
Do While Not rsS.EOF Or rsT.EOF
Mat1 = rsS.Fields("SAP_Aircraft").Value
Mat2 = rsT.Fields("MatriculaReal").Value

If (Mat1 = Mat2) And (Me.DMI_Number = Me.SAP_DMI_Number) Then

If ((Me.SAP_Num_ATA = Me.NumATA) And (Me.SAP_Cat = Me.Cat) And (Me.SAP_Issue_Date = Me.IssueDate) And (Me.SAP_Limit_Date = Me.LimitDate)) Then

'if any diference was found, then nothing happens
}
Else
'add the fields with the differences found to the Diferencias table.
'but doenst recognize the Mat1 value.

DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO Diferencias(mat1) values (" & Mat1 & ") "
DoCmd.RunSQL "INSERT INTO Diferencias(mat2) values (" & Mat2 & ") "

'code to changes the color of the fields with the differences found
End If


Else
'Add the Matricula value from the SAP table that didnt match with any record on the Operational_Technical table
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO Diferencias(mat1) values (" & Mat1 & ") "
End If
rsS.MoveNext
Loop
rsS.Close
'code if the mat1 field from Diferencias table is different than Null the opens a warning advising than differences was found
' this is the form that advise that the differences was found. I didnt want to use a msgbox, because in the form I can change the backcolor, add images and so on
'However I candt find the way to send back the current form and send to the front this Changes form.
DoCmd.OpenForm "Changes", acLayout


End Sub
 

Users who are viewing this thread

Top Bottom