Combo drop down box won't work after adding new record

C

Craig

I have a form, frmAssociates, that displays employee information (name,
address, shift, employee no., etc.) for one employee at a time.

A drop-down box, cmbAssocPicker (in the form header), contains all employees
in the database. Using the drop-down box, the user can select an employee
and the form will display that employee's information.

There is also a button on the form, btnNewAssoc, which opens a new form,
frmAssocEntry, for adding a new employee.

The problem is that after adding a new employee, the new employee's name is
not in the drop-down box. I have to close and re-open the form for the
employee's name to appear.

I would like to be able to instantly see the new employee's name in the
drop-down box, and to potentially be able to select that new employee, to
view his/her information like any other employee already in the list.

I am using Access 2003. Here is the Visual Basic code behind the drop-down
box:

Private Sub cmbAssocPicker_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[AssocNo] = " & Str(Nz(Me![cmbAssocPicker], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Any help is greatly appreciated!

Thanks,
Craig
 
T

Thomko via AccessMonster.com

Hello Craig,

there is the Requery method available for that purpose like this.

cmbAssocPicker.Requery

Depending on how your second form works, you may want to call it on closing
that one like

Forms("frmAssociates").cmbAssocPicker.Requery

HTH
Thomas

I have a form, frmAssociates, that displays employee information (name,
address, shift, employee no., etc.) for one employee at a time.

A drop-down box, cmbAssocPicker (in the form header), contains all employees
in the database. Using the drop-down box, the user can select an employee
and the form will display that employee's information.

There is also a button on the form, btnNewAssoc, which opens a new form,
frmAssocEntry, for adding a new employee.

The problem is that after adding a new employee, the new employee's name is
not in the drop-down box. I have to close and re-open the form for the
employee's name to appear.

I would like to be able to instantly see the new employee's name in the
drop-down box, and to potentially be able to select that new employee, to
view his/her information like any other employee already in the list.

I am using Access 2003. Here is the Visual Basic code behind the drop-down
box:

Private Sub cmbAssocPicker_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[AssocNo] = " & Str(Nz(Me![cmbAssocPicker], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Any help is greatly appreciated!

Thanks,
Craig
 
M

Marshall Barton

Craig said:
I have a form, frmAssociates, that displays employee information (name,
address, shift, employee no., etc.) for one employee at a time.

A drop-down box, cmbAssocPicker (in the form header), contains all employees
in the database. Using the drop-down box, the user can select an employee
and the form will display that employee's information.

There is also a button on the form, btnNewAssoc, which opens a new form,
frmAssocEntry, for adding a new employee.

The problem is that after adding a new employee, the new employee's name is
not in the drop-down box. I have to close and re-open the form for the
employee's name to appear.

I would like to be able to instantly see the new employee's name in the
drop-down box, and to potentially be able to select that new employee, to
view his/her information like any other employee already in the list.

I am using Access 2003. Here is the Visual Basic code behind the drop-down
box:

Private Sub cmbAssocPicker_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[AssocNo] = " & Str(Nz(Me![cmbAssocPicker], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub


That looks ok to me.

The key to getting the new name into the combo box's list is
to Requery the combo box adter the name was added. This
means that the button should open frmAssocEntry in Dealog
mode and then use:
Me.cmbAssocPicker.Requery
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top