Match two numbers and then update

azhar2006

Registered User.
Local time
Yesterday, 17:48
Joined
Feb 8, 2012
Messages
240
Hello guys
I have a database that my dear friend (@arnelgp) helped me design. It contains two tables, the first is called (A) and the second is called (B). Table (A) is the main table in the database. As for table (B), it is a table that I feed with information for specific fields and use a button on the interface of one of the forms. This button runs the programming instructions in (VBA) where this command updates specific fields in table (A) based on the Statistical_Figure field. It matches the number between the two tables and then updates the fields of this record only.
The problem is that when I apply the code, I get the following error
Thanks everyone
Code:
Private Sub cmdExecute_Click()

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strEmployeeName As String
Dim strRank As String
Dim strStatistical_Figure As String
Dim strSQL As String

Set db = CurrentDb
Set rs = db.OpenRecordset("qryNamesWithNewSpecialization", dbOpenSnapshot)

    If rs.RecordCount < 1 Then
        MsgBox "There is no new data to update."
        Set rs = Nothing
        Set db = Nothing
    Exit Sub
    End If

rs.MoveFirst

    While rs.EOF = False
    
        strEmployeeName = rs![EmployeeName]
        strRank = rs![Rank]
        strStatistical_Figure = rs![Statistical_Figure]
        
        strSQL = "UPDATE TableB SET TableB.Statistical_Figure = '" & strStatistical_Figure & _
        "' WHERE ((TableB.EmployeeName)='" & strEmployeeName & "')"
        
        db.Execute strSQL, dbFailOnError
        
        rs.MoveNext
    
    Wend

rs.Close
Set rs = Nothing
Set db = Nothing

MsgBox "Data updated successfully"

End Sub
899.PNG
 
So that field does not exist? :(

This is always the issue when you are given code that you do not understand?
You need to take time to try and understand what you have been given, else you learn nothing. :(
 

Users who are viewing this thread

Back
Top Bottom