AfterUpdate Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two seperate fields, Student Name and Stud ID. On a form, I have one combo box for Student Name and im trying unsuccessfully to have the corresponding Student Number generate itself in a seperate combo box when the name has been selected. Ive tried using the following code

Private Sub Combo5_AfterUpdate(
' Find the record that matches the control
Dim rs As Objec

Set rs = Me.Recordset.Clon
rs.FindFirst "[Stud_ID] = '" & Me![Combo5] & "'
If Not rs.EOF Then Me.Bookmark = rs.Bookmar
End Su

where combo5 is the student name. i get the following error message when i try to select a name in form view

"Run time error '91
Object variable or With block variable not set

Its been a long time since ive used code before so i havn't the foggiest. I will be grateful for any help. Cheers
 
what do you mean by "generate itself in a seperate combo box when the name
has been selected" ?


Luke said:
I have two seperate fields, Student Name and Stud ID. On a form, I have
one combo box for Student Name and im trying unsuccessfully to have the
corresponding Student Number generate itself in a seperate combo box when
the name has been selected. Ive tried using the following code:
Private Sub Combo5_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Stud_ID] = '" & Me![Combo5] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

where combo5 is the student name. i get the following error message when
i try to select a name in form view:
"Run time error '91'
Object variable or With block variable not set"

Its been a long time since ive used code before so i havn't the foggiest.
I will be grateful for any help. Cheers
 
Sorry, was at the end of my mental capabilities last night! What i mean is when the students name is selected in the Student Name combo box, the student's student no will be populated in the Stud ID combo box. The two boxes are meant to work interchangeably, that is you can select the record using either the student's name or their student no. When either combo box is selected, the other combo will find the corresponding detail.
 
I would reference the recordsetclone property directly
Private Sub Combo5_AfterUpdate()
Me.Recordsetclone.FindFirst "[Stud_ID] = '" & Me!
[Combo5] & "'"
If Not Me.RecordsetClone.NoMatch Then
Me.BookMark = Me.RecordsetClone.BookMark
End If
End Sub
-----Original Message-----
I have two seperate fields, Student Name and Stud ID. On
a form, I have one combo box for Student Name and im
trying unsuccessfully to have the corresponding Student
Number generate itself in a seperate combo box when the
name has been selected. Ive tried using the following
code:
Private Sub Combo5_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Stud_ID] = '" & Me![Combo5] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

where combo5 is the student name. i get the following
error message when i try to select a name in form view:
"Run time error '91'
Object variable or With block variable not set"

Its been a long time since ive used code before so i
havn't the foggiest. I will be grateful for any help.
Cheers
 
ah, got it. :)
well, presumably both combo boxes are populated from a Students table - and
the Student Name combo box displays the Student Name but is actually using
the Student ID in the bound column (with a 0" lenth column width)? if all
that is true, then you can set a procedure in the AfterUpdate event of each
control, as

Me!IDCombo = Nz(Me!NameCombo, Null)

and

Me!NameCombo = Nz(Me!IDCombo, Null)

substitute the correct control names, of course.

hth


Luke said:
Sorry, was at the end of my mental capabilities last night! What i mean
is when the students name is selected in the Student Name combo box, the
student's student no will be populated in the Stud ID combo box. The two
boxes are meant to work interchangeably, that is you can select the record
using either the student's name or their student no. When either combo box
is selected, the other combo will find the corresponding detail.
 
Back
Top