How do I set the default value for a Combo Box based on the value selected in the previous record? e.g. when using a form to add new records in a table I want the value for some fields including Combo Boxes to default to the value entered for the same field in the previous record. The user should, of course, be able to over ride the default values.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
How to carry over data from previous record
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » How to carry over data from previous record
- This topic has 9 replies, 3 voices, and was last updated 14 years, 8 months ago.
Viewing 8 reply threadsAuthorReplies-
WSAndrewKKWalker
AskWoody LoungerSeptember 14, 2010 at 3:20 pm #1244413Not sure you can do this without using a chunk of VB and referencing the RecordsetClone and finding the previous record.
I realise that you want to autopopulate with the data from the previous record, but could you not just get them to use CTRL ‘Also, is this just for NEW Records or for ALL records?
If just for NEW Records you could possibly write code on the OnCurrent Event to test for a NEW Record ( If Me.NewRecord Then …..)
then Set Focus to each field that needs a default value
And then use Sendkeys “^'” to retrieve the data from the last record.But you have to be careful with Sendkeys
[Actually I just tried this approach without much success so I think an alternative is needed]
Just some ideas
-
WSkentg
AskWoody LoungerSeptember 14, 2010 at 9:41 pm #1244474My Mother taught me that if I ever used SendKeys, I would surely go straight to hell.
I’ve recently had to do something similar and here’s what I did.
Create module level variables for the fields you want to carry over.
Set them in the after update event of the form
in the on insert event, populate the controls from the module level variables.
-
WSbvitter
AskWoody LoungerSeptember 19, 2010 at 7:47 pm #1245608I think I understand the basic concept but I am missing something in the syntax. In the attached “strEBC_Code” is a Global variable, “Select_BCT” is the first name of the control on the form – a Combo Box.
With these additions to the events already defined to requery the second Combo Box all controls are locked and I can not enter or change variables.
Private Sub Form_AfterUpdate()
strEBC_Code = Me!Select_BCT
End Sub
Private Sub Form_BeforeInsert(Cancel As Integer)
If Not IsNull(strEBC_Code) Then
Me.Select_BCT.Value = strEBC_Code
End IfEnd Sub
Private Sub Form_Current()
Me.Select_PCMs.Requery
End Sub
Private Sub Select_BCT_AfterUpdate()
Me.Select_PCMs.Requery
End Sub
-
WSkentg
AskWoody LoungerSeptember 20, 2010 at 9:30 am #1245688strEBC_Code should be a module level variable and you should name it mstrEBC_Code to make this obvious in your code.
a better test for Not isnull(strEBC_Code) would be to concatenate the variable with an empty string This will tell you that it’s neither null nor an empty string.
I’m assuming that Select_PCMs uses Select_BCT as a filter
also, the current event won’t fire on a new record so you need
Code:if strEBC_Code & "" "" then Me.Select_BCT.Value = mstrEBC_Code call Select_BCT_AfterUpdate
now to “With these additions to the events already defined to requery the second Combo Box all controls are locked and I can not enter or change variables.”
do you mean you can’t enter values into the controls? If so I can’t see why, can you post a stripped out database with the form and just enough data for me to look at.
-
WSkentg
AskWoody Lounger -
WSbvitter
AskWoody Lounger -
WSkentg
AskWoody LoungerSeptember 22, 2010 at 3:25 am #1245921the variables should be module level not global as they are only used by this form.
Don’t try and set the default property at runtime, it screws up in later versions of Access.
the code behind your form should look like this –
Code:Option Compare Database Option Explicit Private mstrEBC_Code As String, mlngPCM_Number As Long Private Sub Form_AfterUpdate() mstrEBC_Code = Me.Select_BCT ' EBC Code mlngPCM_Number = Me.Select_PCMs ' PCM ID End Sub Private Sub Form_BeforeInsert(Cancel As Integer) Me.Select_BCT = mstrEBC_Code Call Select_BCT_AfterUpdate Me.Select_PCMs = mlngPCM_Number End Sub Private Sub Select_BCT_AfterUpdate() Me.Select_PCMs.Requery End Sub
-
WSbvitter
AskWoody LoungerSeptember 22, 2010 at 8:07 pm #1246264I must really be missing something – I think the code below is the same as your guidance (except for the mlngPCM_Number part which is less important) but the EBC Code does not carry over from the prior record. I am using Access 2007 if that makes a difference.
Option Compare Database
Option ExplicitPrivate mstrEBC_Code As String, mlngPCM_Number As Long
Private Sub Form_AfterUpdate()
mstrEBC_Code = Me!Select_BCT
End Sub
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.Select_BCT = mstrEBC_Code
Call Select_BCT_AfterUpdateEnd Sub
Private Sub Form_Current()
Me.Select_PCMs.Requery
End Sub
Private Sub Select_BCT_AfterUpdate()
Me.Select_PCMs.Requery
End Sub
-
WSkentg
AskWoody LoungerSeptember 22, 2010 at 10:22 pm #1246276
Viewing 8 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Phishers extract Millions from HMRC accounts..
by
Microfix
5 hours, 52 minutes ago -
Windows 10 22H2 Update today (5 June) says up-to-date but last was 2025-04
by
Alan_uk
7 hours, 44 minutes ago -
Thoughts on Malwarebytes Scam Guard for Mobile?
by
opti1
10 hours, 53 minutes ago -
Mystical Desktop
by
CWBillow
11 hours, 6 minutes ago -
Meta and Yandex secretly tracked billions of Android users
by
Alex5723
5 hours, 52 minutes ago -
MS-DEFCON 2: Do you need that update?
by
Susan Bradley
1 hour, 17 minutes ago -
CD/DVD drive is no longer recognized
by
WSCape Sand
1 day, 2 hours ago -
Windows 11 24H2 Default Apps stuck on Edge and Adobe Photoshop
by
MikeBravo
1 day, 5 hours ago -
North Face and Cartier customer data stolen in cyber attacks
by
Alex5723
1 day, 3 hours ago -
What is wrong with simple approach?
by
WSSpoke36
19 hours, 46 minutes ago -
Microsoft-Backed Builder.ai Set for Bankruptcy After Cash Seized
by
Alex5723
1 day, 14 hours ago -
Location, location, location
by
Susan Bradley
5 hours, 5 minutes ago -
Cannot get a task to run a restore point
by
CWBillow
1 day, 16 hours ago -
Frustrating search behavior with Outlook
by
MrJimPhelps
1 day, 6 hours ago -
June 2025 Office non-Security Updates
by
PKCano
2 days, 2 hours ago -
Secure Boot Update Fails after KB5058405 Installed
by
SteveIT
5 hours, 25 minutes ago -
Firefox Red Panda Fun Stuff
by
Lars220
2 days, 2 hours ago -
How start headers and page numbers on page 3?
by
Davidhs
2 days, 13 hours ago -
Attack on LexisNexis Risk Solutions exposes data on 300k +
by
Nibbled To Death By Ducks
1 day, 15 hours ago -
Windows 11 Insider Preview build 26200.5622 released to DEV
by
joep517
2 days, 21 hours ago -
Windows 11 Insider Preview build 26120.4230 (24H2) released to BETA
by
joep517
2 days, 21 hours ago -
MS Excel 2019 Now Prompts to Back Up With OneDrive
by
lmacri
2 days, 11 hours ago -
Firefox 139
by
Charlie
2 days, 4 hours ago -
Who knows what?
by
Will Fastie
1 day, 6 hours ago -
My top ten underappreciated features in Office
by
Peter Deegan
2 days, 22 hours ago -
WAU Manager — It’s your computer, you are in charge!
by
Deanna McElveen
16 hours, 11 minutes ago -
Misbehaving devices
by
Susan Bradley
1 day, 18 hours ago -
.NET 8.0 Desktop Runtime (v8.0.16) – Windows x86 Installer
by
WSmeyerbos
4 days, 4 hours ago -
Neowin poll : What do you plan to do on Windows 10 EOS
by
Alex5723
1 day, 3 hours ago -
May 31, 2025—KB5062170 (OS Builds 22621.5415 and 22631.5415 Out-of-band
by
Alex5723
4 days, 3 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.