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

Fields auto filling based on dropdown selection

I am trying to create a form where the user will select a name from a dropdown, and then other fields will populate based on the name selected. Ex: User selects "Smith, John" and then Cust#, Site and Specialty will then populate with John Smith's info. I have the initial dropdown pulling from a query which formats the name field the way I want it. (The source table has the first and last names separated.) The query also has these other fields I want, but I am having a hard time getting them into the form. I have been trying to use DLookup, but I am not having luck getting it to work. If someone came help me get it the work or suggest a better way it would be greatly appreciated!
Jun 14 '10 #1
4 3182
TheSmileyCoder
2,322 Expert Mod 2GB
Do you need the information to be stored in a new record, or do you just want to display it on the form for easy reference?

If I just need to display the information I usually use one-way joins in my form query to get the information.
Example:
Expand|Select|Wrap|Line Numbers
  1. SELECT      tbl_HazardDetails.*,
  2.             tbl_User.tx_UserInitials AS tx_CreatedBy, 
  3.             tbl_User_1.tx_UserInitials AS tx_ChangedBy
  4.  
  5. FROM        tbl_User AS tbl_User_1 
  6. RIGHT JOIN  (tbl_User 
  7. RIGHT JOIN  tbl_HazardDetails 
  8. ON          tbl_User.KEY_User = tbl_HazardDetails.ID_CreatedBy) 
  9. ON          tbl_User_1.KEY_User = tbl_HazardDetails.ID_ChangedBy;
  10.  
This lets me display the userinitials of a person for example "tx_CreatedBy", while the actual value in the record is stored as a long in tbl_HazardDetails.ID_CreatedBy. You can use this approach to pull in multiple information, such as user's address & phone number. I can then bind the ID_CreatedBy to a combobox, and whenever I change my selection in the combobox, the fields bound to tx_CreatedBy will also update automatically.



If however you want to store the information in your new record, you need a different approach. In general this is not advised (see articles about database normalisation), but there are a few cases where it is required.
Jun 15 '10 #2
The form pulls it's data from a single query, so I don't have the multiple sources. My biggest problem has been getting the data into the form. What is the easiest/best way to do this?
Jun 15 '10 #3
I've changed my database araound a bit now to make this a little easier for me. I now have the fields in a table and I think DLookup is the way to go. (I could be wrong here... ) Anyway, I am trying to use the following statement bur I get "#Error" as a result:

=DlookUp("[Provider#]","tblProviderInfo","[Provider]=forms!frmMainForm![Provider]")

Any thoughts?
Jun 15 '10 #4
OldBirdman
675 512MB
I may have completely misread this, but it seems like this thread is about the relationship between a table (or query, which is really a temporary table) and a form.
A form is a window into a table. The purpose is to format, position, and display fields contained in a record of a table.
I am going to assume you want to view and/or edit the fields of your table. I'm also going to assume that table is tblCustomers and contains fields ID, FName, LName, Cust#, Site, and Speciality. ID is the primary key and is Autonum.
I am going to assume the form is frmCustomer, and the Record Source is tblCustomers. There would be fields such as txtFName, txtSite, and any others to display. I'll get to the combobox later. Each textbox on the form should be bound to the table. For textbox txtSite, the Name property should be txtSite, and the ControlSource property should be Site. See assumptions above. This should be done for all the textboxes.
Now you can navigate tblCustomers using the form frmCustomer. The small first, previous, next, and last buttons at the bottom-left of the form border will allow you to do that. Not necessarily in order. The record number isn't necessarily the ID field, but might be. Not as convenient as you want, but at this point it should do everything EXCEPT jump to a specific record based on a name in a combobox.
If your project now works as you need it to, you are ready to add the combobox, which I'm assuming is named cbxSelectName. cbxSelectName will have 2 columns, the ID and the composite name. Set the ColumnWidths property to 1";2" for now, although you will change this to 0";2" later to hide the ID column. ColumnCount will be 2, and BoundColumn will be 1. RowSource will be changed to include the ID field, and should look something like
Expand|Select|Wrap|Line Numbers
  1. SELECT ID, [LName] & ", " & [FName] AS SelName FROM tblCustomers ORDER BY LName, FName
And finally, the OnClick event will need some VBA code to show the chosen record. A simple way is
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSelectName_Click()
  2.   Me.Filter = "ID=" & cboSelectName
  3. End Sub
This will render the Access-supplied navigation buttons worthless. If you need them, we can slightly modify the above.
Jun 17 '10 #5

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

Similar topics

1
by: middletree | last post by:
For an ASp Intranet app, I have some code that should work, but I am not able to make it happen for some reason, after spending considerable time on this. I am pretty thick when it comes to...
1
by: thegame | last post by:
Filling One DataGrid Based on Selection from Another DataGrid - Both in Separate User Controls Hello, I have an interesting dilemma. I have an ASPX page with two user controls (two ASCXs). ...
0
by: ROO | last post by:
Hi Everyone, I have a database table that have 4 field( C1, C2, M1, M2) on my form i have two combo box ComboC and ComboM C1 C2 M1 M2 1 ...
1
by: priyanka.freakout | last post by:
Hi All, In my form I have created a dropdown box which is populated with data from a database on page load and i have also created a dropdwon box and what i intend on doing is displaying data...
5
by: joshua.nicholes | last post by:
I have an access database that consists of two tables.A data collection table and a species list table. The data collection table has about 1500 records in it and the species list has about 600....
4
by: scolivas | last post by:
I think this is a me thing. but can't remember how to do it. I have a form that I am using and would like for a txt box to automatically populate based on what is selected in a combo box. here...
3
by: kandisbarr | last post by:
Please help! I'm new to TheScripts ... I've been stuck on this problem for days and I've lost my mind because of it! I have created a Data Access Page, using Access 2003, named...
4
by: whamo | last post by:
I have the need to populate a field based on the selection in a combo box. Starting out simple. (2) tables tbl_OSE_Info and tbl_Input; tbl_OSE_Info has three fields: Key, OSE_Name and OSE_Wt...
5
by: plumba | last post by:
Hi all. I have two drop down menus, the first a list of Departments, the second a list of Sections. Each Department has a set of Setions, so the Sections dropdown contains complete list of all...
8
by: logicbloke | last post by:
Hello, All the browsers I tested are filling two fields that aren't for logging in, both have different names from the ones on the login form, and eventhough, the browsers fill them, I have read...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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...
0
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
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...

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.