SET TEXTBOX VALUE TO LAST SAVED VALUE

Shafique

Board Regular
Joined
Nov 23, 2018
Messages
119
Hello Everyone
i want to show in textbox its previous saved record's value
e.g......
ID txtdate
1 19-07-22
2 ID 1 = txtdate (19-07-22)
 
txtDate = DLookup("PRDDATE", "MDFPRD", "ID = " & DMax("ID", "MDFPRD", "ID < " & Me.ID))

Our posts are crossing. Note that the red/blue parts are associated with each other.

Firstly, I after looking at your table pic I realized that you need a date based based on the ID that is the highest value but is less than the current record ID value.
So post your actual code or see what happens if you put in any valid ID number instead, such as

txtDate = DLookup("PRDDATE", "MDFPRD", "ID = 5"). Also, form must have the ID field on it, otherwise Me.ID will raise an error. If not there, try adding it (you don't have to make it visible). The PK field should always be on a form/report in case it becomes necessary - such as in this case.
EDIT - company coming; not sure how much time I will have for this today.
i tried it another textbox named txtdate.
but i am very sorry to say that it comes with same error
 

Attachments

  • error.jpg
    error.jpg
    22.1 KB · Views: 4
  • onclick.jpg
    onclick.jpg
    31 KB · Views: 5
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I don't know why you're showing that stuff. I said to put the code in the form AfterUpdate event and you're showing things about a query and a button click. Maybe you'll have to post some file somewhere if you can't figure it out. I did test the code at my end and I got the correct value from my table.
 
Upvote 0
txtDate = DLookup("PRDDATE", "MDFPRD", "ID = " & DMax("ID", "MDFPRD", "ID < " & Me.ID))

Our posts are crossing. Note that the red/blue parts are associated with each other.

Firstly, I after looking at your table pic I realized that you need a date based based on the ID that is the highest value but is less than the current record ID value.
So post your actual code or see what happens if you put in any valid ID number instead, such as

txtDate = DLookup("PRDDATE", "MDFPRD", "ID = 5"). Also, form must have the ID field on it, otherwise Me.ID will raise an error. If not there, try adding it (you don't have to make it visible). The PK field should always be on a form/report in case it becomes necessary - such as in this case.
EDIT - company coming; not sure how much time I will have for this today.
I am very very apology due to last night confusion..
you guide me right way but i cannot understand it. its my fault.
your given solution is working correct
thanks a lot
 
Upvote 0

Forum statistics

Threads
1,224,987
Messages
6,182,164
Members
453,093
Latest member
Soffy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top