473,466 Members | 1,336 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Button in Form to assign field value based on previous record

2 New Member
Sorry i don't have VBA experience but i'm working on a form in Access. Often there will be the same data from entry to entry as the previous record.
So what i want to do is have a little button beside the 4 or 5 fields that i know will likely be repeated and then if the user clicks that button then the field value is copied over from the previous record.

I can't find anything online with this specific example to copy for code. Obviously it would have to have the field name in there somewhere as i'm not looking to copy everything or to have any default values.
Thank you!
Jan 4 '17 #1

✓ answered by NeoPa

As Form Recordsets are often filtered it is unsure that such an approach will always be reliable. There are actually .Recordset & .RecordsetClone properties for a Form though, and some recordset navigation may be helpful to select and get the previous record. I mention .RecordsetClone specifically so that you can access other data without moving off the current record in the Form itself.

I hope that points you in the right direction for a fully-reliable solution. You'll see from this that the question, while seeming relatively straightforward in human terms, is anything but when dealing with databases and Forms in particular. Nevertheless you should have all the tools you need here with which to create your solution.

4 3017
PhilOfWalton
1,430 Recognized Expert Top Contributor
Are you aware that pressing the Ctrl key & "'" (single quote) together does what you want?
On my keyboard the "'" is on the same key as the "@". Anyway, it's ascii code is 39.

Phil
Jan 5 '17 #2
dirtbooksun
2 New Member
Thanks yes i'm already aware of this. I'm looking for a way however to use the mouse to fill in the fields with a single click rather than the keyboard. This is because the mouse will be the primary input method due to the number of required dropdown boxes and if i can create a button that gets clicked to populate fields with the same value as previous this will significantly speed up the data entry which is the aim. I had the same setup on a previous database in Filemaker pro and it was great - but that program doesn't use visual basic so i can't just copy it over...
Jan 8 '17 #3
PhilOfWalton
1,430 Recognized Expert Top Contributor
So suppose your 5 fields are named "MyField1", "MyField2" ... "MyField5" and the undetlying recordsource for the form is "MyQuery", then you need a command button against each field that has code something like the following:-

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Command1_Click()
  3.  
  4.     If IsNull(MyField1) Then         ' Blank Field
  5.         MyField1 = DLast("Myfield1", "MyQuery")
  6.     End If
  7.  
  8. End Sub
  9.  
Be aware that this will copy the last record entered. Regardless of whether MyQuery is sorted, It will be the last record in the underlying table.

The Ctrl & single Quote will produce the same result, so your user will have 2 methods of copying the previous information, but the latter method does not check that the field is empty before copying, so may be best avoided unless one is careful.

Phil
Jan 8 '17 #4
NeoPa
32,556 Recognized Expert Moderator MVP
As Form Recordsets are often filtered it is unsure that such an approach will always be reliable. There are actually .Recordset & .RecordsetClone properties for a Form though, and some recordset navigation may be helpful to select and get the previous record. I mention .RecordsetClone specifically so that you can access other data without moving off the current record in the Form itself.

I hope that points you in the right direction for a fully-reliable solution. You'll see from this that the question, while seeming relatively straightforward in human terms, is anything but when dealing with databases and Forms in particular. Nevertheless you should have all the tools you need here with which to create your solution.
Jan 8 '17 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: TRAX | last post by:
Here's my problem: I've got a table cities with the following tables: zipcode, city, province and table provinces: a table with: province_id, provincename cities.province and province.province_id...
2
by: Tony Schoeffler | last post by:
I have a data entry form used for adding records tied to a particular checklist number. I currently have to enter the checklist number on each new data entry form. It would be desirable to have...
4
by: | last post by:
Something really common I'm sure and I'm surprised it's not just a field property option. The previous record's field value can be retrieved and copied into the current corresponding field by...
2
by: nasse | last post by:
i found this code on the internet that copy value from the previous record to the new record. Private Sub Ordrenummer_AfterUpdate() Const cQuote = """" Me!Ordrenummer.DefaultValue = """" &...
2
by: jmoore1999 | last post by:
I need to write a t-sql query that will take the value of the previous record into consideration before calculating the current row's new column value... Here's the situation... I have a...
3
by: Chris | last post by:
Is it possiable to have a iif function in a query where it looks at the next record. for example if I run the query which lists years and if the results in record 2 equals the result in record 1...
8
by: Jeff | last post by:
A client wants a press of the Enter key in a field on a continuous form to grab the value of that field from the previous record. But if they have typed a value and then hit Enter it shouldn't. ...
1
by: roveagh1 | last post by:
Hi I've been using the 2 year old link below to repeat values from previous record field into current corresponding field. It's worked fine for text but the last piece of advice was to use the same...
1
by: EORTIZ | last post by:
I have 2 tables: Claims table- claim ID, Member_ID, service_from_date, service_end_date. Plan table- Member_ID, Plan_ID, Plan_from_date, Plan_end_date. The same member_id can have multiple...
1
by: hlock | last post by:
Access 2007 on XP - I have a table that has: claim trans date examiner 1 1/2/08 MB 1 1/2/08 MB 1 2/9/08 MB 1 5/21/08 DG 1 7/18/08 DG 2 1/5/08 KY 2 3/1/08 KY
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.