Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Requery listbox 1

Status
Not open for further replies.

Duane8889

Programmer
Dec 14, 2001
46
0
0
US
Hello
I'm trying to update a lstbox after adding an entry to it through a textbox. I suppose it works like I add make an entry to the textbox that goes to a table. The listbox shows records from the table from it's RowSource. I hope that made sense. It will show the update if I leave the form and come back but not immediately. Someone suggested using a Requery. I tried using a Requery in the textbox afterUpdate, beforeUpdate...
Code:
Private Sub txtAddEmployee_AfterUpdate()
    Dim ctxt As Control
    Dim ctlst As Control
    Set ctlst = lstEmployees

    ctlst.Requery      ' refresh lstEmployees
End Sub
but no change to listbox contents until I leave the form and come back again.

Duane
 
You didn't say us where and how the new entry is made in the table ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I did mention the entry to the table would be through a textbox. The table is sorted alphabetically so the entry point to the table depends on what the name begins with. Maybe this is what you are asking for...
Code:
Private Sub cmdAddEmployee_Click()
On Error GoTo Err_cmdAddEmployee_Click

    txtAddEmployee.SetFocus
    DoCmd.GoToRecord , , acNewRec
    Dim ctlst As Control
    Set ctlst = lstEmployees
    ctlst.Requery
    
Exit_cmdAddEmployee_Click:
    Exit Sub

Err_cmdAddEmployee_Click:
    MsgBox Err.Description
    Resume Exit_cmdAddEmployee_Click
    
End Sub

Duane
 
I'd try this:
Private Sub txtAddEmployee_AfterUpdate()
DoCmd.RunCommand acCmdSaveRecord
DoEvents
lstEmployees.Requery ' refresh lstEmployees
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top