Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old January 24th, 2006, 12:45 AM
eetarnold@kc.rr.com
Guest
 
Posts: n/a
Default Complex ComboBox Functions for Teachers

Hi Gurus,

As I've read in other posts the past couple of days, I've read many
great posts and haven't figured out how I can solve this problem...I'm
trying to make a form very user friendly for a group of teachers--who
are not computer teachers.

I have a main form named "frmProgressReports" based on a record source
"qryStudents," which has StudentID, FullName: [FirstName] & " " &
[LastName], LastName, and FirstName.

In frmProgress is an unbound combobox, "comboStudents," which also has
the row source: SELECT qryStudents.StudentID, qryStudents.FullName,
qryStudents.LastName, qryStudents.FirstName FROM qryStudents ORDER BY
qryStudents.LastName;

ComboStudents has column widths 0";4";0";0"---FullName is what appears
in the combo list.

I'd like comboStudents to have this functionality:

(1)
Include an item in the list of students (FullName) that says something
like 'Click to Add Student.' If the teacher clicks on the
comboStudents and selects that item, a data entry form (frmStudents,
based on the students table) is opened, set to a new record, and focus
set on the FirstName field. The 'Click to Add Student' item could be
the first and default record in the underlying students table--I could
maybe just add it into the FirstName field.

(2)
If a teacher selects a student already entered in the underlying table,
comboStudents refreshes, moves frmProgressReports to the right record,
and sets the focus to a control on a subform in frmProgress called
subProgressReports, in which progress data can be entered for that
student.

(3)
If a teacher tries to type a student's name (first and then last name)
into comboStudents (field showing is the expression FullName), an on
not in list event or some other event catches the first and last names,
opens the frmStudents form in add mode, parses(?) the first and last
names, and puts them into the FirstName and LastName fields so the
teacher doesn't have to retype them in this form.

I know enough to know that the first 2 functions are the crucial ones,
and that I need clarification on what code to use and when. Something
like the 3rd function would be nice, but would require some effort...

I'd greatly appreciate any advice/assistence that could be provided.

Respectfully,

Arnold

  #2  
Old January 24th, 2006, 02:05 AM
Wayne Gillespie
Guest
 
Posts: n/a
Default Re: Complex ComboBox Functions for Teachers

On 23 Jan 2006 16:38:10 -0800, "eetarnold@kc.rr.com" <eetarnold@kc.rr.com> wrote:
[color=blue]
>Hi Gurus,
>
>As I've read in other posts the past couple of days, I've read many
>great posts and haven't figured out how I can solve this problem...I'm
>trying to make a form very user friendly for a group of teachers--who
>are not computer teachers.
>
>I have a main form named "frmProgressReports" based on a record source
>"qryStudents," which has StudentID, FullName: [FirstName] & " " &
>[LastName], LastName, and FirstName.
>
>In frmProgress is an unbound combobox, "comboStudents," which also has
>the row source: SELECT qryStudents.StudentID, qryStudents.FullName,
>qryStudents.LastName, qryStudents.FirstName FROM qryStudents ORDER BY
>qryStudents.LastName;
>
>ComboStudents has column widths 0";4";0";0"---FullName is what appears
>in the combo list.
>
>I'd like comboStudents to have this functionality:
>
>(1)
>Include an item in the list of students (FullName) that says something
>like 'Click to Add Student.' If the teacher clicks on the
>comboStudents and selects that item, a data entry form (frmStudents,
>based on the students table) is opened, set to a new record, and focus
>set on the FirstName field. The 'Click to Add Student' item could be
>the first and default record in the underlying students table--I could
>maybe just add it into the FirstName field.
>
>(2)
>If a teacher selects a student already entered in the underlying table,
>comboStudents refreshes, moves frmProgressReports to the right record,
>and sets the focus to a control on a subform in frmProgress called
>subProgressReports, in which progress data can be entered for that
>student.
>
>(3)
>If a teacher tries to type a student's name (first and then last name)
>into comboStudents (field showing is the expression FullName), an on
>not in list event or some other event catches the first and last names,
>opens the frmStudents form in add mode, parses(?) the first and last
>names, and puts them into the FirstName and LastName fields so the
>teacher doesn't have to retype them in this form.
>
>I know enough to know that the first 2 functions are the crucial ones,
>and that I need clarification on what code to use and when. Something
>like the 3rd function would be nice, but would require some effort...
>
>I'd greatly appreciate any advice/assistence that could be provided.
>
>Respectfully,
>
>Arnold[/color]

1. Set the row source of comboStudents to -

SELECT -999 As StudentID, "<Add New Student>" As FullName, "aaa" As LastName, "x" As FirstName
From qryStudents
UNION SELECT StudentID, FullName, LastName, FirstName
FROM qryStudents
ORDER BY LastName;

This will add an item to the top of the dropdownlist displaying <Add New Student>

2. Set the AfterUpdate event of comboStudents to -

************************************************** ***************
Sub comboStudents_AfterUpdate()

If Me.comboStudents = -999 Then
DoCmd.OpenForm "frmStudents", , , , acFormAdd
Else
With Me.RecordSetClone
.FindFirst "[StudentID]=" & Me.comboStudents
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End If

Me.comboStudents = Null

End Sub
************************************************** ***************

If the user selects <Add New Student>, frmStudents will open at a new record ready for them to enter the student
details.
If they select anything else frmProgressReports will navigate to the corresponding record.

3. This can be done by using the NotInList event of the combo to open frmStudents at a new record, similar to 2 above.
The difficulty is automatically parsing the student name into first / last name. Consider -

Billy Bob Thornton (Billy Bob Thornton or Billy Bob Thornton)
Jill St James (Jill St James or Jill St James)
Rip van Winkle (Rip van Winkle or Rip van Winkle)


Wayne Gillespie
Gosford NSW Australia
  #3  
Old January 24th, 2006, 02:05 AM
MGFoster
Guest
 
Posts: n/a
Default Re: Complex ComboBox Functions for Teachers

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

For (1) create another query that looks like this:

SELECT StudentID, FullName, LastName, FirstName
FROM qryStudents

UNION ALL

SELECT 0, "<Click to Add Student>", NULL, NULL
FROM qryStudents

ORDER BY LastName

Save it and make this query name the RowSource of the ComboBox.

The "<Click to add student>" will be the top item in the combo list.
When that is selected use the ComboBox's AfterUpdate event to add the
new student info (see below).

For (2) use the AfterUpdate event of the ComboBox to change the form's
RecordSource property and then set the focus to the control in the
subform. E.g.:

Private Sub cboStudents_AfterUpdate()

' Assumes that Column(0) is the Bound column
If Not IsNull(Me!cboStudents) Then
If Me!cboStudents = 0 Then
' Run the add new student routine
' Open the form in dialog mode, which waits
' until the form is closed to resume the VBA code flow.
DoCmd.OpenForm "frmStudents", acNormal, _
DataMode:=acFormAdd, WindowMode:=acDialog
Else
Me.RecordSource = "SELECT * FROM Students WHERE StudentID=" & _
Me!cboStudents
Me!subProgressReports!MyControl.SetFocus
End If
End If

End Sub

If the StudentID is a string the WHERE clause would look like this:

WHERE StudentID = '" & Me!cboStudents & "'"

For (3) you can see how that would work from the above: i.e., grab the
info from the frmStudents & place it in the parent form, etc.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQ9WJj4echKqOuFEgEQIbWQCeNCQS+gYmAoRTyxyuwNWxas UYAN4An0oJ
WKCb7N6b6jhc+oxC1YvQnaN4
=WK4M
-----END PGP SIGNATURE-----

eetarnold@kc.rr.com wrote:[color=blue]
> Hi Gurus,
>
> As I've read in other posts the past couple of days, I've read many
> great posts and haven't figured out how I can solve this problem...I'm
> trying to make a form very user friendly for a group of teachers--who
> are not computer teachers.
>
> I have a main form named "frmProgressReports" based on a record source
> "qryStudents," which has StudentID, FullName: [FirstName] & " " &
> [LastName], LastName, and FirstName.
>
> In frmProgress is an unbound combobox, "comboStudents," which also has
> the row source: SELECT qryStudents.StudentID, qryStudents.FullName,
> qryStudents.LastName, qryStudents.FirstName FROM qryStudents ORDER BY
> qryStudents.LastName;
>
> ComboStudents has column widths 0";4";0";0"---FullName is what appears
> in the combo list.
>
> I'd like comboStudents to have this functionality:
>
> (1)
> Include an item in the list of students (FullName) that says something
> like 'Click to Add Student.' If the teacher clicks on the
> comboStudents and selects that item, a data entry form (frmStudents,
> based on the students table) is opened, set to a new record, and focus
> set on the FirstName field. The 'Click to Add Student' item could be
> the first and default record in the underlying students table--I could
> maybe just add it into the FirstName field.
>
> (2)
> If a teacher selects a student already entered in the underlying table,
> comboStudents refreshes, moves frmProgressReports to the right record,
> and sets the focus to a control on a subform in frmProgress called
> subProgressReports, in which progress data can be entered for that
> student.
>
> (3)
> If a teacher tries to type a student's name (first and then last name)
> into comboStudents (field showing is the expression FullName), an on
> not in list event or some other event catches the first and last names,
> opens the frmStudents form in add mode, parses(?) the first and last
> names, and puts them into the FirstName and LastName fields so the
> teacher doesn't have to retype them in this form.
>
> I know enough to know that the first 2 functions are the crucial ones,
> and that I need clarification on what code to use and when. Something
> like the 3rd function would be nice, but would require some effort...
>
> I'd greatly appreciate any advice/assistence that could be provided.
>
> Respectfully,
>
> Arnold
>[/color]
  #4  
Old January 24th, 2006, 02:35 AM
Bob Quintal
Guest
 
Posts: n/a
Default Re: Complex ComboBox Functions for Teachers

"eetarnold@kc.rr.com" <eetarnold@kc.rr.com> wrote in
news:1138063090.268604.117430@g49g2000cwa.googlegr oups.com:
[color=blue]
> Hi Gurus,
>
> As I've read in other posts the past couple of days, I've read
> many great posts and haven't figured out how I can solve this
> problem...I'm trying to make a form very user friendly for a
> group of teachers--who are not computer teachers.
>
> I have a main form named "frmProgressReports" based on a
> record source "qryStudents," which has StudentID, FullName:
> [FirstName] & " " & [LastName], LastName, and FirstName.
>
> In frmProgress is an unbound combobox, "comboStudents," which
> also has the row source: SELECT qryStudents.StudentID,
> qryStudents.FullName, qryStudents.LastName,
> qryStudents.FirstName FROM qryStudents ORDER BY
> qryStudents.LastName;
>
> ComboStudents has column widths 0";4";0";0"---FullName is what
> appears in the combo list.
>
> I'd like comboStudents to have this functionality:
>
> (1)
> Include an item in the list of students (FullName) that says
> something like 'Click to Add Student.' If the teacher clicks
> on the comboStudents and selects that item, a data entry form
> (frmStudents, based on the students table) is opened, set to a
> new record, and focus set on the FirstName field. The 'Click
> to Add Student' item could be the first and default record in
> the underlying students table--I could maybe just add it into
> the FirstName field.
>[/color]

http://www.mvps.org/access/forms/frm0043.htm
[color=blue]
> (2)
> If a teacher selects a student already entered in the
> underlying table, comboStudents refreshes, moves
> frmProgressReports to the right record, and sets the focus to
> a control on a subform in frmProgress called
> subProgressReports, in which progress data can be entered for
> that student.[/color]

http://www.mvps.org/access/forms/frm0005.htm

[color=blue]
> (3)
> If a teacher tries to type a student's name (first and then
> last name) into comboStudents (field showing is the expression
> FullName), an on not in list event or some other event catches
> the first and last names, opens the frmStudents form in add
> mode, parses(?) the first and last names, and puts them into
> the FirstName and LastName fields so the teacher doesn't have
> to retype them in this form.
>[/color]

http://www.mvps.org/access/forms/frm0015.htm
[color=blue]
> I know enough to know that the first 2 functions are the
> crucial ones, and that I need clarification on what code to
> use and when. Something like the 3rd function would be nice,
> but would require some effort...
>
> I'd greatly appreciate any advice/assistence that could be
> provided.
>
> Respectfully,
>
> Arnold
>[/color]
http://www.mvps.org/access/ is a very useful site! Thank you Dev
Ashish, Arvin Meyer and Felix Kasza.

--
Bob Quintal

PA is y I've altered my email address.
  #5  
Old January 24th, 2006, 10:55 AM
eetarnold@kc.rr.com
Guest
 
Posts: n/a
Default Re: Complex ComboBox Functions for Teachers

Thanks Wayne and MGFoster for the code, and Bob for the links (which I
had tried to make sense of previously).

I really apreciate your help, and will study the different code you
gave. This is kind of why I'm confused. I realize that with
programming, all things are pretty much possible, and different code
can do the same thing.

I am wondering which of the code above more popular, efficient, stable,
etc. Is there a rhyme or reason to use one approach over the other?

Also, good point about the "Rip van Winkle" possibility. Maybe I
should add yet another field...

Thanks again,
Arnold

  #6  
Old January 24th, 2006, 12:35 PM
Arnold
Guest
 
Posts: n/a
Default Re: Complex ComboBox Functions for Teachers

One last question--multiple entries in combobox.

In comboStudents, why would there be some name duplication occuring, as
well as overwriting of existing list items with those names being
selected? That seems to be happening--in the table named Students,
multiple names have been created, apparently just by selecting them in
comboStudents. Is there a way to protect against this?

Thanks again,
Arnold

  #7  
Old January 24th, 2006, 12:55 PM
Wayne Gillespie
Guest
 
Posts: n/a
Default Re: Complex ComboBox Functions for Teachers

On 24 Jan 2006 04:28:19 -0800, "Arnold" <eetarnold@kc.rr.com> wrote:
[color=blue]
>One last question--multiple entries in combobox.
>
>In comboStudents, why would there be some name duplication occuring, as
>well as overwriting of existing list items with those names being
>selected? That seems to be happening--in the table named Students,
>multiple names have been created, apparently just by selecting them in
>comboStudents. Is there a way to protect against this?
>
>Thanks again,
>Arnold[/color]

It sounds like you have comboStudents bound to the StudentID field in the table.
If comboStudents is to be used as a search field it must be UNBOUND. (ControlSource empty)

You can use the combo as a search field OR a data field, but not both.

Wayne Gillespie
Gosford NSW Australia
  #8  
Old January 24th, 2006, 05:35 PM
ea3666@ozanam.org
Guest
 
Posts: n/a
Default Re: Complex ComboBox Functions for Teachers

Thanks Wayne,

However, comboStudents is unbound--there's nothing in the control
source. Yet it still does this.

However, the subform in this form, subProgressReports, is bound to
StudentID.

Is this part of the problem?

  #9  
Old January 30th, 2006, 12:05 AM
Arnold
Guest
 
Posts: n/a
Default Re: Complex ComboBox Functions for Teachers

I ended up using Wayne's approach above--Thanks again. I'll also
mention that the combobox, ComboStudents, also had a double-click event
that should allow the user to double-click a name to open the
frmStudents to the name's record for editing (in case a teacher spelled
it wrong).

However, with the above "<Add New Student>" code, an error now occurs
when double-clicking an name in the list: Run-time error '2137: You
can't use Find or Replace now. Do you know why this happens?

Private Sub ComboStudents_DblClick(Cancel As Integer)

DoCmd.OpenForm "frmStudents", acNormal, "", "", , acNormal
DoCmd.GoToControl "StudentID"
DoCmd.FindRecord Me!StudentID, acEntire, False, , False, , True
If Me!StudentID = 1 Then
DoCmd.GoToRecord , , acNewRec
End If
DoCmd.GoToControl "FirstName"

Exit_ComboStudents_Click:
Exit Sub

Err_ComboStudents_Click:
MsgBox Err.Description
Resume Exit_ComboStudents_Click

  #10  
Old January 30th, 2006, 12:35 AM
Wayne Gillespie
Guest
 
Posts: n/a
Default Re: Complex ComboBox Functions for Teachers

On 29 Jan 2006 15:54:08 -0800, "Arnold" <eetarnold@kc.rr.com> wrote:
[color=blue]
>I ended up using Wayne's approach above--Thanks again. I'll also
>mention that the combobox, ComboStudents, also had a double-click event
>that should allow the user to double-click a name to open the
>frmStudents to the name's record for editing (in case a teacher spelled
>it wrong).
>
>However, with the above "<Add New Student>" code, an error now occurs
>when double-clicking an name in the list: Run-time error '2137: You
>can't use Find or Replace now. Do you know why this happens?
>
>Private Sub ComboStudents_DblClick(Cancel As Integer)
>
>DoCmd.OpenForm "frmStudents", acNormal, "", "", , acNormal
> DoCmd.GoToControl "StudentID"
> DoCmd.FindRecord Me!StudentID, acEntire, False, , False, , True
> If Me!StudentID = 1 Then
> DoCmd.GoToRecord , , acNewRec
> End If
> DoCmd.GoToControl "FirstName"
>
>Exit_ComboStudents_Click:
>Exit Sub
>
>Err_ComboStudents_Click:
> MsgBox Err.Description
> Resume Exit_ComboStudents_Click[/color]

If you double click on the <Add New Student> you won't be able to use the FindRecord because it uses a false StudentID
to differentiate it from a "true" record. Split the 2 functions with an IF statement.

If Me!StudentID = 1 Then
DoCmd.GoToRecord , , acNewRec
DoCmd.GoToControl "FirstName"
Else
DoCmd.FindRecord Me!StudentID, acEntire, False, , False, , True
DoCmd.GoToControl "StudentID"
End If


Wayne Gillespie
Gosford NSW Australia
  #11  
Old January 30th, 2006, 03:35 AM
Arnold
Guest
 
Posts: n/a
Default Re: Complex ComboBox Functions for Teachers

Wayne--thanks for helping out again this weekend.

I included the IF statement, but the form still opens with the 2137
error. The code highlights this line:

DoCmd.FindRecord Me!StudentID, acEntire, False, , False, , True

  #12  
Old January 30th, 2006, 05:15 AM
Wayne Gillespie
Guest
 
Posts: n/a
Default Re: Complex ComboBox Functions for Teachers

On 29 Jan 2006 19:28:21 -0800, "Arnold" <eetarnold@kc.rr.com> wrote:
[color=blue]
>Wayne--thanks for helping out again this weekend.
>
>I included the IF statement, but the form still opens with the 2137
>error. The code highlights this line:
>
>DoCmd.FindRecord Me!StudentID, acEntire, False, , False, , True[/color]

Let's try replacing the FindRecord with searching frmStudents' recordsetclone for a matching record, and setting the
form's bookmarks if the record is found.

**untested**

Dim frm As Form

If Me!StudentID = 1 Then
DoCmd.GoToRecord , , acNewRec
DoCmd.GoToControl "FirstName"
Else
Set frm = Forms("frmStudents")
With frm.RecordsetClone
.FindFirst "[StudentID]=" & Me.StudentID
If Not .NoMatch Then
frm.Bookmark = .Bookmark
End If
End With
End If

Set frm = Nothing


Wayne Gillespie
Gosford NSW Australia
  #13  
Old January 30th, 2006, 11:55 AM
Arnold
Guest
 
Posts: n/a
Default Re: Complex ComboBox Functions for Teachers

That sovled it. Thanks A LOT Wayne.

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles