473,387 Members | 1,453 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,387 software developers and data experts.

How to fill in field based on combobox selection (was VBA Access)

I am very new at this. I have written a few functional databases, but everything i have learned has mostly come from this website.... so bear with me. I am trying to get information to automatically update. In the scenario i am using 2 tables. I have a part_number_table and a receiving_table. All of the part numbers and the descriptions are in the PN_table. The receiving_form is to assign a date, vendor, purchase order number, ect to the rec_table. What i need is .....

I have the part number on the rec_form coming from the pn_table from a combo box. When the pn is chosen i would like to have the description automatically filled in on the rec_form , from the pn_table, using on lost focus. I know it can be done, but i am extremely lost. How do i compare the number entered on the rec_form, to a number on the pn_table, and then enter the description from the pn_table on the rec_form.

Please help (the company i work for has told me to take an access class, but that has not occured yet)
Aug 17 '08 #1
5 2649
ADezii
8,834 Expert 8TB
You don't give me much to work on, so I'll make several assumptions. Substitute your own values where required:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboPN_LostFocus()
  2. Dim varDescription As Variant
  3.  
  4. If Not IsNull(Me![cboPN]) Then
  5.   'If the Part Number is a String
  6.   varDescription = DLookup("[Description]", "PN_Table", _
  7.                            "[Part_Num] = '" & Me![cboPN] & "'")
  8.   'If the Part Number is Numeric
  9.   varDescription = DLookup("[Description]", "PN_Table", _
  10.                            "[Part_Num] = " & Me![cboPN])
  11.     Forms!rec_form![txtDescription] = varDescription
  12. End If
  13. End Sub
Aug 17 '08 #2
NeoPa
32,556 Expert Mod 16PB
I'd consider using the AfterUpdate event in place of the LostFocus one for better results.
Aug 20 '08 #3
missinglinq
3,532 Expert 2GB
I agree! You really don't want the code running if the user simply tabs thru the combobox, which LostFocus would do, especially if the combobox has no item selected. A Null value would pop an error, I believe.

Also, crazyhorse, in the future please take the time to come up with a thread title that gives members a general idea of your problem. Since this is an Access/VBA forum, the title "VBA Access" really doesn't say much.

Welcome to Bytes!

Linq ;0)>
Aug 20 '08 #4
thank you for your help, i did end up using afterupdate, and i ended up using a subform on my for that is hidden. One day i will get better at this.
Aug 21 '08 #5
missinglinq
3,532 Expert 2GB
Of course you will! Glad you got it working!

Linq ;0)>
Aug 21 '08 #6

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

Similar topics

5
by: Steve | last post by:
I have an unbound combobox in the form header of a continuous form. The selection in the combobox sets the where clause in a querydef which determines QryPFrmInventoryManagement. The following code...
4
by: Sherwood Botsford | last post by:
Table Markers ID (Primary Key) This&That PointClass (Combo box) Points Table PointClasses PointClass (primary key) Points (number) Description (Text)
5
by: Geoff Portbury | last post by:
I'm a swimming club coach. I have a data base for recording times at various meets. I have a FORM for entering times called SWIM TIMES. When I enter the swimmers name ID, eg FOR01 for Doug Ford I...
2
by: Jeremy Dillinger | last post by:
I have a program setup to pull data from a database. My database table has things such as (category, Item, price, etc.) In my program I want to have multiple list boxes that will have a pull down...
7
by: grummanf6f | last post by:
Hello Gurus, this probably is real simple for you but for me it's a bummer. I have one table in which I have basic data collected of schools. I have another data that is detailed info on the...
3
by: Magnus | last post by:
Im using a set combobox (ComboBox1) to provide a selection of records from a database table. I have a typed dataset (DataSet1) that contains the typed datatable (DataTable1) that the combobox is...
2
by: jujubean | last post by:
I have a form with five comboboxes. In the first, the user can select one of four items. The other four comboxes are hidden. Based on the selection made in combobox one, I would like one of the...
1
by: peasedm | last post by:
Okay this one has me stumped. I have a table called Review_Statements with the following columns: statementid type statement1 statement2 statement3 I have a form called SR_Review with an...
9
by: Brett_A | last post by:
I have a form where the first field is a dynamic drop-down that pulls from a db (Access). The fields associated with the query are task_id, task_name and task_rate. The field has the value of...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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,...

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.