473,729 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select value from query when cbo item selected

3 New Member
Hello

I have a table (MainTable) with the fields
(PK)ID
(cbo)from_dept
document_date
reference_numbe r
last_reference

I have a query on the first 4 fields that is sorted to give the last reference_numbe r for each from_dept This is the value I need to be automatically displayed in last_reference when the from_dept is selected from it's cbo The idea being that when I enter a new record I select from_dept and the last_reference for that from_dept pops up automatically and I add the next sequential value into reference_numbe r
ad nauseaum

I have attached the file if someon can have a look and for me - I am now wondering after trying lookups, queries and failing to get codes written properly if I need another table into which the reference_numbe r is entered rather than finding the data from the MainTable ???

Does anyone have any ideas? If you look at query_reference the value I need to be seen in last_reference is LastOfreference _number.

I just can't get this last bit sorted out.
Attached Files
File Type: zip Mail Log Database Original.zip (331.7 KB, 145 views)
Aug 12 '09 #1
5 3736
ChipR
1,287 Recognized Expert Top Contributor
If from_dept is not unique in your table, you'll want to create a query that groups by from_dept and selects from_dept and the max of last_reference. With that information, you can write an After_Update event for the from_dept combo box which will look up the value and put it in the last_reference text box. Something like:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmbFromDept_AfterUpdate()
  2.     txtLastReference = DLookup("last_reference", "query1", "from_dept = " & cmbFromDept)
  3. End Sub
Aug 12 '09 #2
ezechiel
53 New Member
indeed, _AfterUpdate is the way to go but I have a question..

In your main table, is "last reference" referring to a record with a given "from_dept" and "reference" where the "document_d ate" is the most recent? Or is it something else?

And sorry, I can't open your file, I only have Access 2003.
Aug 12 '09 #3
ellie
3 New Member
Hello (sorry for the late reply. I am in Saudi Arabia and Thurs/Fri is the weekend) Thanks for the responses.

Further information - my query is sorted like this: maintable.from_ dept (group ascending), maintable.docum ent_date (last), maintable.ID (max), maintable.refer ence_number (last)

so I can select the field 'last_reference ' value from the field LastOfreference _number value, based on the unique ID for each record. However (not sure here if it is an access 2007 thing) but I can't get AfterUpdate to work.

I have managed to get a subform based on the same query to work perfectly (in that I can select a from_dept and the last reference number used pops up in the subform, I can then enter the next reference number for the new record) but it's a bit messy - data table on the form.

ezechiel - I tried to save it in 2003 for you but I can't "dumb it down" in 2007 or even save it in compatible format without losing current programming. Sorry.

ChipR - I tried your solution but no dice.

I'd prefer to have a textbox using an AfterUpdate option that works as well as the subform, but nothing seems to work. Thoughts??
Aug 15 '09 #4
ellie
3 New Member
Hi I solved this one using a subform (AfterUpdate wouldn't work on my computer) Thanks to ChipR and ezechiel for your help :-) Much appreciated. Now I have Access2007 version sorted out I need to do the same in Access2003 (I may be back for help on this later :-) )

Thanks again Ellie
Aug 16 '09 #5
ezechiel
53 New Member
you're welcome, but ChipR is the one who gave you the solution :)
He's a Jedi, I'm still a padawan..
Aug 19 '09 #6

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

Similar topics

7
7898
by: Felix Natter | last post by:
hi, I have a php-Script which gets passed a Boat-ID and this is used to mark an element in a <select> as the default: <select name="boote" multiple="multiple" size="5"> <option value='43'>Aisha</option> <option value='40'>Amsterdam</option> <option value='55'>Asmaa</option> <option value='20'>Beau Rivage</option> <option value='48'>Blue Perl</option>
3
2349
by: Rob | last post by:
Hi, I've got a small javascript problem and I'm kinda stuck. I'm using classic ASP. I have a select box which is populated by a database query and there is a buttom that when clicked it will move the selected item from the first select box and move it to another select box: document.form2.list.options = new Option(count + 1 + ". " + name,company); Then I want to remove it from the first select box:
19
3563
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main form, the subform returns the records based on the two criteria. The criteria used on the main form are values selected in two list boxes. When the user clicks on the first list box (lstCollege), it returns values in the second list box...
2
2733
by: DC Gringo | last post by:
I have two listboxes, the first of which is an autopostback=true that allows multiple row selection. When I select multiple values (by holding down CTL) in the first one, it should query the second one. I seem unable to do this as it only sends back the first item I select whether I have the CTL key down or not. Upon the return trip, I can select another one, but it still only sends value for the last one I selected. -- MY LISTBOX --...
5
2176
by: GTi | last post by:
Whats wring with this code? <select class=EditField size="1" name="PlantUnitID" title="Select line"> <option value="0" >Standalone Unit</option> <option value="1" selected >Connected Unit 1</option> <option value="1" selected >Connected Unit 2</option> </select> <span onclick="NewWindow('pluginpage.html?EditUnitGUID='+this.form.PlantUnitID.options.value+'&DoPostBack=1','namexx',200,310);"
5
4084
by: Matthew Wells | last post by:
I have a listbox set to simple multi select. For this example, users only select one item at a time. I have command buttons on the form for First, Previous, Next, Last, New (record). The form and listbox are unbound. The listbox rowsource is a value list. The list box has about sixty items in it. Each item in the list box corresponds to a record in the database. When a user selects a row in the list box, the record is retrieved. The...
1
8062
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just a commandbutton on my form). The biggest problem I'm having is that I can't (don't know how) populate a combobox on static items such as "True, False, Any." The Any field, would be selected by the user to find all records where that fields is...
2
2819
by: phpnewbie26 | last post by:
I currently have two drop down menus where the second one is populated from the first one. My second drop down menu should be able to do multiple selection. I have searched online and found out how to do so (add in multiple and put brackets after name), but unfortunately when I retrieve the data on the next page, it seems that none of the selections were added to the variable array. On the other hand, it "POST"-ed the null value which is 1. My...
6
7570
by: phpnewbie26 | last post by:
My current form has one multiple select drop down menu as well as few other drop down menus that are single select. Originally I had it so that the multiple select menu was first, but this created the problem that when I went to select the other drop down menus, the selections i made on the multiple select one would clear. Then I had tried putting the multiple select menu last so that the selections wouldn't clear but then after clicking the...
0
8921
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9427
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9284
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9148
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8151
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
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 we have to send another system
3
2165
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.