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

Autofill Comboboxes Based on Another Combobox (Access 2007)

I Have data entry form in which there are few comboboxes named as city,dist,state. so i want to autofill the dist, state comboboxes on adding value in city combobox. please help me.
Nov 13 '15 #1
10 3847
strive4peace
39 Expert 32bit
Add the columns you want to automatically fill to the RowSource for the City combobox.

Change the ColumnCount and ColumnWidths properties

on the City AfterUpdate event, set the values in the other controls.

Here is some code you can modify:

Expand|Select|Wrap|Line Numbers
  1. with me.City_controlname
  2.    if isnull(.value) then exit sub
  3.    me.State_controlname = .column(#)
  4. end with
WHERE
# is the column number -- column index starts with 0 (zero), so column(1) is really column 2
Nov 13 '15 #2
zmbd
5,501 Expert Mod 4TB
How are your comboboxes setup for the row-source, bound-column, and control-source?

IF these are bound, and setup in a normalized database, in the after_update event (as S4P has mentioned) you need to set the [controlname].value to match the value of the related table field. You might also need to me.repaint to get the form to update.
Nov 13 '15 #3
strive4peace
39 Expert 32bit
I often do what the poster is doing ... have a table of 42,000+ zip codes that I use to fill city and state.

Reference Database with Zip Codes, Countries, States, Area Codes, Airlines, Airports, ... voltages, flowers, ...
http://www.AccessMVP.com/strive4peace/Reference.htm

I did try storing FKs instead of values for city , state, and zip but it was incredibly slow and made searching and filtering more difficult ... so now I store text and autofill on zip because my zips table is not always right. This saves me time entering addresses and lets me correct the looked-up values.
Nov 13 '15 #4
Thanks you s4p N zmbd. iam new user of access so please explaine me in simpal way
When i select A or B or C in cmbcity then cmbDist autofill with L and cmbstate with X And onselect D or E or F IN cmbcity then autofill cmbdistcwith M and cmbstate with Y.
Nov 14 '15 #5
strive4peace
39 Expert 32bit
Hi,

lets just take this one step at a time.

First, set up the combobox to show the information you want to populate automatically.

Go to the design view of your form. If you already have a combobox, great. If not, then create one.

Turn on the Property Sheet if it is not showing. Press Alt-Enter.

Click on the combobox to select it.

On the Property Sheet, clickon the DATA tab.

click in the RowSource property.

To the right, you will see 3 dots ... -- this is called the Builder Button. click on it.

You will be taken to the designer and it looks like a query. Add the other fields you want to automatically populate and display.

Pick how you want it to be sorted.

Click on the Datasheet view to make sure this is what you want.

Count the columns that you have and remember this.

Also, make a note about how wide each column should be (I used NotPad to do this).

For instance, if you have 3 columns with City, District, and State, you might write:

1.5; 1.5; .5
(this is inches -- if you are using centimeters or another unit, your widths will be different).

Close the designer and click YES to save the changes.

On the Property Sheet, set:
ColumnCount (for instance, 3)
ColumnWidths -- this will be what you wrote into NotePad.

Save the form design and go to the form view.

When you drop the list of choices for your combo box, you should also see the other 2 columns.

Once you make it this far, post back and we will help you further.
Nov 14 '15 #6
S4p! I do this as u say so what is next step...
Nov 14 '15 #7
strive4peace
39 Expert 32bit
Great! Now you see that when you pick something from the combo box, the information you want is known too. So after you update the combo by picking a value, you want code to push that information to other controls.

Select the City control
On the Property Sheet, click on the Event tab and then in the After Update event.

Click on the Builder Button ... off to the right.

This will put you into code between the Sub declaration and End Sub

Rather than telling you exactly what to do, I will give you some code you can modify:

Expand|Select|Wrap|Line Numbers
  1.     with me.City_controlname
  2.        if isnull(.value) then exit sub
  3.        me.District_controlname = .column(#)
  4.        me.State_controlname = .column(#)
  5.     end with
WHERE
City_controlname is the NAME property of the city controlname
District_controlname is the NAME property of the district controlname
State_controlname is the NAME property of the district controlname

# is the respective column number for the information (remember column numbering starts at 0 so 1 is really column 2

~~~~~~~~~ Add Option Explicit ~~~~~~~~~

if the top of your module does not have a statement that says Option Explicit, then add this:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit  ' require variable declaration
~~~~~~~~~ Compile ~~~~~~~~~

Whenever you change code, references, or switch versions or operating environment, or modify objects with code behind them, you should always compile and save before executing.

from the menu in a VBE (module) window: Debug, Compile
(Alt-F11 to switch to the code window)

Fix any errors on the yellow highlighted lines.
Add needed references and remove missing references if necessary
(from the menu: Tools, References...)

keep compiling until nothing happens (this is good!) -- then Save


also be sure, before compiling, to use Option Explicit at the very TOP of each module so variables that are not declared or are misspelled will be picked up

~~~

if you made it to here without any problem, Save and test!
Nov 14 '15 #8
zmbd
5,501 Expert Mod 4TB
... be sure, before compiling, to use Option Explicit at the very TOP of each module so variables that are not declared or are misspelled will be picked up
Recommended for anyone that uses VBA in any Office installation is to make this automatic.
IN Office 2013 installations (and this works for most other versions):
Open the VBE (<alt><F11> or even <ctrl><g>)
Once open: In the menu (no ribbon here :)
Tools>Options
Editor tab:
UNCHECK-Mark the "Auto Syntax Check" option
Your code will still flag as error (typically red) if there is malformed code - just that annoying message pop-up will go away here!
CHECK-Mark the "Require Variable Declaration" option
This will now insert the Option Explicit in every new module created. This means that the programmer will now be required to include the Dim variablenamehere As typecasthere for each variable used in the code.
[OK]
Nov 14 '15 #9
Thanks S4P. I set code as u said but is not work. the set up of cmbcity as there are 3 column 0 for city 1 for dist and 3 for state and i used code exactly as u mention so what is wrong with this. AND When i used another way as i set control source of cmbDIST As =[cmbcity].[Column](1)
and for cmbstate as=[ cmbcity]. [column](2)
and its work but a problem with this way that in form cmbdist and cmbstate were autofills but in table bound with form are not updated.what i do now?
Nov 21 '15 #10
strive4peace
39 Expert 32bit
if you are showing values, as opposed to filling them with code so they can be edited, the ControlSource needs to be blank.

If you are simply echoing information that canNOT be edited, then you will assign the ControlSource using equations and NOT use code.
Nov 21 '15 #11

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

Similar topics

10
by: ZaphodBBB | last post by:
HI I have a form with 2 comboBoxes. The first comboBox gives me a list of customers to select from. I would like to have the second comboBox populated with the names of Departments. I only want...
5
by: Ira Solomon | last post by:
Hi: Any quick opinions on Access 2007? Has anyone got this to coexist with Access 2003? Thanks Ira
49
by: Allen Browne | last post by:
If you are looking for opinon on what's useful in Access 2007, there's a new article at: http://allenbrowne.com/Access2007.html Covers what's good (useful features), what's mixed (good and bad),...
4
by: Neil | last post by:
Just found out that the Microsoft Rich Textbox does not support full text justification, since it's based on Version 1.0 of the RichEdit Window Class, and full text justification is only available...
16
by: Neil | last post by:
I posted a few days ago that it seems to me that the Access 2007 rich text feature does not support: a) full text justification; b) programmatic manipulation. I was hoping that someone might...
6
by: pouj | last post by:
what i want to do is basically have form where my selection in the combox make the diffrence with what the form reports. this is what the underlying informaion is.... software is access 2007 i...
4
by: lupo666 | last post by:
Hi everybody, this time I have three problems driving me nuts :-((( (1) I have a report with 20 or so Yes/No "squares". Is there a way to either hide/show the "square" or change the yes/no...
3
by: HTIDIRECT | last post by:
I am currently creating a form that requires me to have multiple comboboxes which have various options with different values. What I am having a problem with is finding a javascript snippet that...
4
by: HiGu | last post by:
I have a combobox that has the following as its rowsorure: SELECT qryMIMATRIX.A_JOBNO FROM qryMIMATRIX;The problem is that the combobox drops down but when I try to select any record, the status...
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:
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
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
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
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,...
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
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...

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.