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

Home Posts Topics Members FAQ

How to set a combo box default value to the previously selected value

5 New Member
Hello All,

I’d like to make an enquiry as to how to set the default value in a combo box to the previously select value in MS access 2003.

I have 50 or so possible items that can be selected from the combo box and scrolling though them each selection time will be too time consuming for the user. As the majority of the time the user will be selecting the same value repeatable, it makes sense to me to try and set the default value to the previously selected one!?!? Is my logic correct?

When I try to do this I get diverted to accesses expression builder, however I am unable to find the correct expression to do this?

Any advise?

D
Oct 30 '07 #1
10 10035
FishVal
2,653 Recognized Expert Specialist
Hi, Declining.

Take a look at Repeating values for a field in several records thread.
Oct 30 '07 #2
missinglinq
3,532 Recognized Expert Specialist
In the code editor in the AfterUpdate event for your combobox you can use this to set the default (assuming it's a text field)

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourComboBox_AfterUpdate()
  2.   YourComboBox.DefaultValue = """" & Me.YourComboBox & """"
  3. End Sub
Welcome to TheScripts!

Linq ;0)>
Oct 30 '07 #3
Declining
5 New Member
Thanks for the quick response guys however my problems continue.....

The default value is updated to the previously selected value (i used the ComboBox.DefaultValue = """" & Me.PartNumbers & """" solution) on the first command button click however on subsequent entries nothing is added. It appears i need to reset the event procedure how do i do this?

Thanks,
Oct 31 '07 #4
FishVal
2,653 Recognized Expert Specialist
Thanks for the quick response guys however my problems continue.....

The default value is updated to the previously selected value (i used the ComboBox.DefaultValue = """" & Me.PartNumbers & """" solution) on the first command button click however on subsequent entries nothing is added. It appears i need to reset the event procedure how do i do this?

Thanks,
Post the whole AfterUpdate event handling sub.
Oct 31 '07 #5
Declining
5 New Member
Private Sub PartNumbers_AfterUpdate()

PartNumbers.DefaultValue = """" & Me.PartNumbers & """"

End Sub
Nov 1 '07 #6
missinglinq
3,532 Recognized Expert Specialist
The DefaultValue should remain the same until you either make a new selection from your combobox or until you close your form! When closing your form, this DefaultValue will be lost, and will only be "reset" when you open the form again and make a selection from the combobox.

what exactly did you mean by the statement

(it worked) on the first command button click however on subsequent entries nothing is added.
Also, FishVal asked you to post all of your code in the AfterUpdate event, but all you show is the setting of the DefaultValue. Where's the code showing what you do with the selected value after the selection?

Linq ;0)>
Nov 1 '07 #7
Declining
5 New Member
Hi MissingLinq, FishVal

"It worked"
a default value of the previous value selected was inserted into the combo box. Per MissingLing's discription.
The DefaultValue should remain the same until you either make a new selection from your combobox or until you close your form! When closing your form, this DefaultValue will be lost, and will only be "reset" when you open the form again and make a selection from the combobox.
My new problem however now is it appears once i enter the default value i cannot enter additional information using the command button event below

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. On Error GoTo Err_Command1_Click
  3. 'Add new record
  4.     DoCmd.GoToRecord , , acNewRec
  5. 'Run query to update record
  6.     DoCmd.SetWarnings False
  7.     stDocName = "Studentsquery"
  8.     DoCmd.OpenQuery stDocName, acNormal, acEdit
  9.     DoCmd.SetWarnings True
  10. 'Run update query once predetermined classsize reached
  11.     If (DCount("classsize", "Information", "classsize = False") = 15) Then
  12.     DoCmd.SetWarnings False
  13.     stDocName = "UpdateQuery"
  14.     DoCmd.OpenQuery stDocName, acNormal, acEdit
  15.     DoCmd.SetWarnings True
  16.     End If
  17.  
  18. Exit_Command1_Click:
  19.     Exit Sub
  20.  
  21. Err_Command1_Click:
  22.     MsgBox Err.Description
  23.     Resume Exit_Command6_Click
  24.  
  25. End Sub
Thanks,
Decline
Nov 1 '07 #8
FishVal
2,653 Recognized Expert Specialist
Hi, Decline.

It would be a good idea to post [Studentsquery] and [UpdateQuery] as well.
Nov 1 '07 #9
Declining
5 New Member
No problem

Update query
Every time a record is saved it adds a No count to classsize. Once the query is run all No, are turned to Yes (i use the No's to count to class size 15, it reset then to yes once complete, and i start again)
Expand|Select|Wrap|Line Numbers
  1. UPDATE Information SET [Information].classsize= Yes
  2. WHERE ((([Information].classsize)=No));
Student query
This query inquires in an linked file for a description that matches the Partnumber chosen:
Expand|Select|Wrap|Line Numbers
  1. UPDATE Sheet1 INNER JOIN Information ON Sheet1.[Part Number] = [Information].classsize SET [Information].Description = sheet1.description;
Nov 1 '07 #10
FishVal
2,653 Recognized Expert Specialist
You'll easier find a problem via debugging the code. Read the following tutorial.
WIP: Debugging in VBA

Just for starters.
toggle breakpoints on
  • the 1st row
  • the rows with DoCmd.OpenQuery ....
  • the row with if DCount(......
check first whether code execution flow reaches that points.
Nov 1 '07 #11

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

Similar topics

5
by: Harry Haller | last post by:
<select name="cboPlaces" id="cboPlaces"> <option value="3">Countryside</option> <option value="4">Forest</option> <option value="5">Mountain</option> <option value="6">Desert</option> <option...
2
by: Robert | last post by:
Am using a nested continuous bound subform to add multiple records to the underlying table. One of the fields is based on a limit to list combo box. Any suggestions on best way to progressively...
4
by: Mark L. Breen | last post by:
Hello Guys and Galls, I use combos on my forms. The code to initialise the combos is as follows Dim dsPIDTypes As DataSet dsPIDTypes = PartDB.GetPIDTypes ' Returns a dataset object...
7
by: Ausclad | last post by:
Ok, ill try again..... It seems fairly simple. I have two combo boxes in a datagrid. The datagrid is bound to a a table in a dataset. The two combo boxes are bound to a single data table...
1
by: sangram | last post by:
how to select a default value of combo box in run time, i have select some value from database ,depending on this i have to set the value of combox box... advance thanks..
8
by: salad | last post by:
I was wondering how you handle active/inactive elements in a combo box. Let's say you have a combo box to select an employee. Joe Blow has been selected for many record however Joe has left the...
12
by: Doogie | last post by:
How do I make a value the default value for a combo box in ASP 3.0? What I have below does NOT work, yet I've seen it in HTML file examples before (and works if I put it in a HTML file by itself,...
4
by: Dave | last post by:
I wasn't sure how to search for previous posts about this, it felt real specific. Ok so here's the database & problem: I have 4 combo boxes: cboServer, cboPolicy, cboDB, and cboApplication. ...
3
by: KingKen | last post by:
I have the task of adding a value to a textbox based on the selected value in a combo box. The trouble is, I cant seem to access the selected content in the combo box so as to store it in a variable,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
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 ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.