Go Back   Access World Forums > Microsoft Access Discussion > Queries

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 10-13-2018, 06:50 AM   #1
basilyos
Newly Registered User
 
Join Date: Jan 2014
Posts: 191
Thanks: 52
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

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 by basilyos; 10-13-2018 at 07:13 AM.
basilyos is offline   Reply With Quote
Old 10-13-2018, 11:11 AM   #2
June7
Newly Registered User
 
Join Date: Mar 2014
Posts: 728
Thanks: 0
Thanked 168 Times in 168 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 offline   Reply With Quote
Old 10-13-2018, 12:59 PM   #3
GinaWhipp
AWF VIP
 
GinaWhipp's Avatar
 
Join Date: Jun 2011
Location: Ohio, USA
Posts: 5,150
Thanks: 20
Thanked 859 Times in 844 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...

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

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

Tags
query

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 04:56 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


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