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

Continuous Forms--Combo Box with Variable Row Source

Folks,

Here's a write-up I did for our developer wiki. I don't know if the
whole rest of the world has already figured out how to do this, but I
hadn't ever seen it implemented, and had spent a lot of time trying to
figure it out, over the years. It finally dawned on me a couple of
weeks ago how to do this.

A couple of notes:
1) This is written for a different audience than CDMA; it's written for
independent consultants who are doing development work using the
database my NGO produces. This means the voice may sound funny in this
context ("We" instead of "I") and there may be some times where I
assume some context based on our application, but this seems to be
fully usable in just about any context--I hope so, anyway.
2) Watch for line wrapping in the code.
3) I'd love to hear any feedback about this.

Jeremy
--
Jeremy Wallace
Fund for the City of New York
metrix dot fcny dot org
====
For a long time we've struggled with figuring out how to have a combo
box's row source be different for different records in a continuous
form. We think we've figured out a decent way to approach this. It
doesn't work for a datasheet view, but you can get pretty close to
mimicing this in a continuous form, so that shouldn't be too much of a
hitch.

We built this form for a client with specific needs, but it's quite
generalizable. In this case, the client has a program in which
volunteers mentor students in reading. Volunteers may team up to work
with students, alternating days. When the client takes attendance, she
wants to be able to select which student is there and, based on which
student is selected for this record, we'll fill the rowsource of a
combo box with all of the volunteers who have signed up to work with
that student. It's a pretty simple need, and one we see quite often.
But up until now, we've not seen a good solution to this problem (This
is not to say no one's come up with a solution before, just that we've
not seen any).

Here's how we did it.

The basic plan is to use two fields in place of the one combo box for
the volunteer txtVolunteer and cboVolunteer. txtVolunteer will be
disabled, and will hold a formula to display what is chosen from
cboVolunteer. cboVolunteer will only be partially visible, and will
fire its dropdown method upon gaining focus.

The form (which will be used as a subform, but can be built
independently) has five fields: Date, Student, Student Attendance,
Volunteer, and Volunteer Attendance. Actually, there are two other
fields that the user doesn't really know about. One of them is the
AttendanceID field, the PKey of the table behind most of the data on
the form. The other is that second Volunteer control, txtVolunteer, and
that's the key to how this works.

[Image here: continuous form set up to look a lot like a datasheet.
Five controls, two of which are combo boxes]

This looks fairly standard. But as soon as you click in the
cboVolunteer, you can see that something is not quite as you would
expect it to be:

[Image here: that same form with one of the combo boxes showing the
list. The list is flush left with the drop-down arrow, not the usual
flush right.]

Why is the combo box opening off to the right side like that? Because
it is so narrow, and the control displaying not cboVolunteer, but
txtVolunteer. Have a look at the form in Design View:

[Image here: that same form in design view. you can see the combo box
in question is built of two controls, a text box and a combo box that's
so narrow all you can see is the drop-down arrow.]

You can see the cboVolunteer highlighted, and the start of the formula
in txtVolunteer. Here's the full formula:

=IIf(IsNull([cboVolunteer]),"",DLookUp("SortName","tblContacts","ContactID
= " & [cboVolunteer]))

Remember to make this control Disabled and Locked.

Now all we need is two small pieces of code to make this work. This
first one sets the RowSource of cboVolunteer, when that control gets
the focus. It also immediately forces the combo to display its list fo
values.

Private Sub cboVolunteer_GotFocus()
Me!cboVolunteer.RowSource = "SELECT tblContacts.ContactID,
tblContacts.SortName" _
& " FROM tblCustom_EW_StudentVolunteerConnection " _
& " INNER JOIN tblContacts ON
tblCustom_EW_StudentVolunteerConnection.VolunteerI D =
tblContacts.ContactID" _
& " WHERE " _
& " tblCustom_EW_StudentVolunteerConnection.StudentID = " &
Me.Student & " AND " _
& " tblCustom_EW_StudentVolunteerConnection.StartDate <= Date() AND
" _
& " tblCustom_EW_StudentVolunteerConnection.EndDate >= Date();"
Me.cboVolunteer.Dropdown
End Sub

This next one just move focus to the next control after a value is
selected in cboVolunteer.

Private Sub cboVolunteer_AfterUpdate()
Me.VolunteerAttendance.SetFocus
End Sub

Because txtVolunteer never receives focus (it's disabled), tabbing out
of the Student Attendance field brings focus straight to the combo box.
As soon as this happens, the RowSource for the combo is set to just
those volunteers who are associated with this student, and the lsit of
volunteers is dropped down. At this point the user can use arrow keys,
type a name, or select a name with the mouse. As soon as the mouse is
clicked or the user hits Enter or Tab, focus moves to the Volunteer
Attendance field.

Please let us know if you implement this, and give us any feedback
you've got, so we can tweak anything that needs to be tweaked in this
method.

May 16 '06 #1
0 2906

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

Similar topics

19
by: Nicolas Pernetty | last post by:
Hello, I'm looking for any work/paper/ressource about continuous system simulation using Python or any similar object oriented languages (or even UML theory !). I'm aware of SimPy for...
1
by: D Boyd | last post by:
Im trying to get the name of a bound control on a continuous form in Access. So that I can get the value of any text field. This is what Im looking to do.... The user enters a value for number...
3
by: Richard Hollenbeck | last post by:
I have the following query in my form's code: Private Function Get_Data(fieldNum As Integer) Dim strSQL As String Dim db As DAO.Database Dim rs As DAO.Recordset strSQL = "SELECT & "", "" & ...
3
by: DavidB | last post by:
I have a Snapshot Control in a continuous form and I want the source for the control to be different for each instance of the continuous data (based on one of the fields in the recrod source for...
7
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently...
1
by: clusardi2k | last post by:
In chapter 23, it explains how to navigate the tables of a DataSet. I'm looking for the definition of "AllOrders1", below. I.E.: How is it created, explained to me in a step by step fashion, and...
5
by: bittman | last post by:
I have code as follows: Dim conn As New ADODB.Connection Dim rst As New ADODB.Recordset conn.ConnectionString = "Provider=MSDAORA;Password=tr7025ds;User ID=system;Data Source=WIN10" conn.Open...
3
Minion
by: Minion | last post by:
I hate to even post this message as I probably know the answer before I begin. Still there are several problems facing me with this particular challenge. First though I'll goto into the overview...
4
by: Adam Tippelt | last post by:
Situation: I'm using a continuous form to display a lot of information stored in a datasheet. I'm using the form because it allows me to display multiple rows of information per 'record' which is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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

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.