Go Back   Access World Forums > Microsoft Access Discussion > Queries

Thread Tools Rate Thread Display Modes
Old 10-13-2018, 06:50 AM   #1
Newly Registered User
Join Date: Jan 2014
Posts: 210
Thanks: 56
Thanked 3 Times in 3 Posts
basilyos is on a distinguished road
update last record

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

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

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

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

Last edited by basilyos; 10-13-2018 at 07:13 AM.
basilyos is offline   Reply With Quote
Old 10-13-2018, 11:11 AM   #2
Newly Registered User
June7's Avatar
Join Date: Mar 2014
Posts: 1,273
Thanks: 0
Thanked 307 Times in 307 Posts
June7 will become famous soon enough
Re: update last record

Did you try building and running query object to perform that update? If it works then it can be translated into VBA code.
To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression. Attachment Manager is below Advanced editor window, click Go Advanced below Quick Reply window.
June7 is online now   Reply With Quote
Old 10-13-2018, 12:59 PM   #3
GinaWhipp's Avatar
Join Date: Jun 2011
Location: Ohio, USA
Posts: 5,276
Thanks: 20
Thanked 873 Times in 858 Posts
GinaWhipp has a spectacular aura about GinaWhipp has a spectacular aura about
Re: update last record

Actually you can put the variable in the UPDATE query if you SQL behind the Form...

    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

Gina Whipp
Microsoft MVP (Access 2010-2015)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
GinaWhipp is offline   Reply With Quote


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Child Record based on Parent update KEKeogh Forms 2 05-24-2016 08:42 PM
Update Record ID to another Record ID in the Same Table and Update Related Records EternalMyrtle General 6 08-23-2013 12:39 PM
Update Query - uses selected record to make calculation and uses this to update all! DSLNVL Queries 3 08-01-2011 05:50 PM
Check if subform record exists before update / after update? misscrf Forms 0 07-08-2011 11:36 AM

All times are GMT -8. The time now is 05:37 PM.

Microsoft Access Help
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post

Sponsored Links

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World