update last record (1 Viewer)

basilyos

Registered User.
Local time
Today, 14:03
Joined
Jan 13, 2014
Messages
252
hello guys,


i want to run an update query to update the last record in a table from multiple table

N.B: each table from where i want to bring data contains just one field and one record


this my code

Code:
UPDATE tbl_Sanctions SET tbl_Sanctions.Code01_01Year = [tbl_01Years_Code01].[txt_Text], tbl_Sanctions.Code01_05Year = [tbl_05Years_Code01].[txt_Text], tbl_Sanctions.Code01_10Year = [tbl_10Years_Code01].[txt_Text]
  WHERE (((tbl_Sanctions.ID)=DMax([ID],[tbl_Sanctions])));
any help?




i tried this way


Code:
Dim obj As New DataObject
        Dim lastID As Long
        lastID = DMax("ID", "tbl_sanctions")
        obj.SetText lastID
        obj.PutInClipboard


but how can i put the lastID as criteria in the update query
 
Last edited:

June7

AWF VIP
Local time
Today, 13:03
Joined
Mar 9, 2014
Messages
5,423
Did you try building and running query object to perform that update? If it works then it can be translated into VBA code.
 

GinaWhipp

AWF VIP
Local time
Today, 17:03
Joined
Jun 21, 2011
Messages
5,901
Actually you can put the variable in the UPDATE query if you SQL behind the Form...

Code:
    Dim strSQL As String
    
    strSQL = "UPDATE tbl_Sanctions " & _
                "SET tbl_Sanctions.Code01_01Year = [tbl_01Years_Code01].[txt_Text], tbl_Sanctions.Code01_05Year = [tbl_05Years_Code01].[txt_Text], tbl_Sanctions.Code01_10Year = [tbl_10Years_Code01].[txt_Text] " & _
                    "WHERE (((tbl_Sanctions.ID)=" & lastID & ")))"
              CurrentDb.Execute strSQL, dbFailOnError
 

Users who are viewing this thread

Top Bottom