473,378 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Assign default values from the last record

(Before I post I must say that this Forum has assisted me greatly in solving many if not all of my problems and for that I am very grateful)


At present I have a form that has 4 sub forms within, the purpose of the form is to store customer’s information and their associated salary deductions. Eg. The main form will have customer name, account number, payroll number etc, and sub 1 form will allow you to select what loans he/she is paying and also how much, while another will allow you to select what savings account he/she is contributing to and how much etc. What I want is that once the form is filled out for the customer and saved the next person who is attempting to add another form for the same customer will be presented with the records for the last one entered as to speed up data entry.
Jan 28 '09 #1
5 4387
beacon
579 512MB
I think you can setup your form's OnLoad() event to populate each field with data from your query by using SQL.

The only thing I would do is make sure that the query your form is using as a record source has an autonumber/ID field:

Expand|Select|Wrap|Line Numbers
  1. 'declare a variable for the controls (textboxes, etc.) on your form
  2. Dim strSQLControl1, strSQLControl2, strSQLControl3
  3.  
  4. 'set the first variable equal to the first record on the query when you sort descending, which is the opposite of the true 1st record (if you don't put descending it will select the true 1st record)
  5. strSQLControl1 = "SELECT Top 1 [YourField for Control 1] FROM [YourQuery] ORDER BY [the autonumber/ID field] DESC"
  6.  
  7. Me.Control1 = strSQLControl1
  8.  
  9. 'repeat for the other controls as necessary
  10.  
I haven't tried this out, so I'm not 100% sure it works, but I think it's close.

If you want to give the user the choice to fill in the fields with default information, create a command button and put the above code in the OnClick() event instead.
Jan 28 '09 #2
Thanks, but will it work as I want the last records specific to that customer selected be available. So if the user select John Doe, the last record entered for john doe will populate
Jan 28 '09 #3
Dan2kx
365 100+
i would suggest the bookmark functionality, specifically RecordSetClone
you can use the wizard to ceate a button that navigtes to records (and creates the code) then nick it and put it where you need, or follow clicky.
Jan 28 '09 #4
beacon
579 512MB
@trinismooth
I think you can add the WHERE clause to your SQL statement, but to do so in the OnLoad() event would mean that you would probably have to select a customer from another form and then pass the customer as a parameter to the current form.

I guess it's all dependent on how you actually select the customer. If the customer is chosen on the current form (say from a dropdown), you could add the SQL statement to the AfterUpdate() event for the Customer combo box.

If someone else has a better way, you might want to try that instead since, if you have a lot of info that needs to be filled in, this method could potentially be heavy on the code and might take a while to write.

I'm not really familiar with the bookmark method, although I have seen it used to filter a form. If I remember correctly, I think there's a different article than what Dan suggested Microsoft's support website that gives examples of searching a recordset and bookmarking a record, although it may be the same one as in the msdn.
Jan 28 '09 #5
NeoPa
32,556 Expert Mod 16PB
I suggest you may have to control the setting of your defaults by the changing of the record in your main form. In other words the code to set the defaults would have to reside in the Current event of your main form, even though the defaults are being set on one of your sub-forms.
Jan 29 '09 #7

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

Similar topics

33
by: n00m | last post by:
import socket, thread host, port = '192.168.0.3', 1434 s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2.connect((host, 1433))...
1
by: Sophie Bradshaw | last post by:
i was wondering if anyone could possibly help me! i have a ms access database, and in one of the tables, one of the fields is a lookup column, with several possible values. what i want to do is...
2
by: Todd D. Levy | last post by:
I have a table of Country names & Country codes in alphabetical order. This is a lookup table that a number of other tables use to populate the Country field via a drop down Combo Box on the...
11
by: David Messner | last post by:
Ok I know this is simple but the statement eludes me... I have a date field where I want the default value on the data entry form's date field to be the last date entered. I figure I can do this...
2
by: dskillingstad | last post by:
I'm trying to assign a custom value to a textbox. Here's what I have. I've created a module and "default value" code for a textbox which generates a custom auto-number (yyyy-0000) when a New...
2
by: dBNovice | last post by:
Hi all! I have 3 separate forms: Tasks, Subtasks, and Elements. All 3 is related by TaskId and Subtasks and Elements are related by SubtaskID. In the DB after I add a task, I want to be able to...
5
by: MN | last post by:
Hello, I have a customer table and another table that I need to prepopulate with special customer IDs, unique and not sequential. Is there a way to configure Access to assign the customer ID to...
11
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
4
by: Avi | last post by:
Hi I am creating web application in which i want to assign by default values to the property which i had created my own. In that one of the property is of type color and i am unable to assign...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.