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

combo boxes

I would like some help on the use of combo boxes.
I have created a form and named it Customers. This form's record
source is a table, also named Customer.
I would now like to add an unbound combo box, name it cbosearch, which
would return a selected record in a textbox, which I will name
txtresult.

The cbosearch record source is another table named AGENCIES which has
two fields: TOWN and ADDRESS.

I would that my cbosearch, will display only one field, TOWN (so that
I can see all Towns in the list) and on the OnChange event, display in
the txtresult, the second field: ADDRESS.

Can any one help me with the code?
Nov 12 '05 #1
1 2650
Can more than one address be in the same town? If so a simple textbox for
your result wont quite do the trick. If only 1 agency per town then this
would work

Note: This routine makes use of DAO (you will have to create a reference to
this library "Microsoft DAO 3.5". (maybe someone else could post an ADO
equivilent so you dont have to make a reference, my ADO is rusty yet and I
wouldnt want to miss-lead you)

put the following code behind a button that you place on your form, we'll
call it "Search" and we'll name our combo box "cboSearch"
<aircode>
Dim rs as Recordset
Dim strSQL As String

strSQL = ""SELECT ADDRESS FROM AGENCIES WHERE TOWN='" & cboSearch.Value
& "'"
Set rs = CurrentDB.OpenRecordset(strSQL,dbOpenSnapshot)
If rs.EOF And rs.BOF Then
Msgbox "No Matching Address for the selected town!",vbOkOnly,"No
Match"
Else
txtresult = rs.Feilds("ADDRESS")
End If
'lets be good programmers and clean up our mess after we make it :)
rs.Close
Set rs = Nothing
</aircode>

The idea here is to do it all in code since we are dealing with unbound
controls, first I create an sql query that will select the address from the
agencies table with a matching town to what the user selected. I placed a
little bit of error handling so you could see how to react for bad entries
(just in case your combo box is not set to "limit to list") if the .EOF and
..BOF flags are true then no records were returned. Otherwise we found a
result, we are _assuming_ one agency for one town. At that point simply
retrieve the value of the ADDRESS field and assign it to our txtresults
textbox. Finally, becuase we are dealing with recordsets, I close it and
free it from memory (I believe its better _not_ to get in the habbit of
letting Access clean up memory usage.) Thats it, we now have our results
for the user to see.

HTH

Mike Krous
"Paolo" <jp***@tin.it> wrote in message
news:9f**************************@posting.google.c om...
I would like some help on the use of combo boxes.
I have created a form and named it Customers. This form's record
source is a table, also named Customer.
I would now like to add an unbound combo box, name it cbosearch, which
would return a selected record in a textbox, which I will name
txtresult.

The cbosearch record source is another table named AGENCIES which has
two fields: TOWN and ADDRESS.

I would that my cbosearch, will display only one field, TOWN (so that
I can see all Towns in the list) and on the OnChange event, display in
the txtresult, the second field: ADDRESS.

Can any one help me with the code?

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: vgrssrtrs | last post by:
<html> <head> <script language="JavaScript"> <!-- /* *** Multiple dynamic combo boxes *** by Mirko Elviro, 9 Mar 2005 *** ***Please do not remove this comment
1
by: FZ | last post by:
Hi Gang, I was wondering if a generous person might be able to walk me through what I believe is a pretty simple task. I actually have significant Access experience, but I haven't done it in...
0
by: Krisa | last post by:
Hello all, I just discovered something (stop me if you've heard this before....) that was causing me a significant performance hit when opening a form with subforms. To speed up loading the...
0
by: Tom | last post by:
I have some very strange issues with combo boxes on a tab control. Here's the scenario: I have a Windows Forms form that has a tab control on it, with two (2) tabs. Tab 2 happens to have a number...
5
by: jjyconsulting | last post by:
Newbie needing some help. I have a tblParticipants. The fields include gender, education_level, income, occupation etc., I'm trying to create a form where a user can run a query from the form and...
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. ...
6
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
1
by: Dave | last post by:
Hello all, First I'd like to apologize...This post was meant to be put in my previous post, but I tried many times without success to reply within my previous post. Now here goes... I have a...
2
by: Dave | last post by:
I have 3 tables of information feeding into 4 combo boxes on my main form (DR Form). I have as many list boxes (acting as text boxes) as there are fields in each one of the 3 tables. Once...
2
by: someshbakliwal | last post by:
Hi, I have created some autopopulating combo boxes on my HTML page (script- Javascript). so these combo boxes are autopopulated with choices made in previous combo boxes. The problem I am facing is...
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:
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
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...
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
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...
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...

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.