Update combo box list after adding or deleting record

G

Guest

I use a combo box "cmboJobNamep3" to find records on my form "frmJobs". I
want to be able to add a new record and delete a record on the same form and
have placed "cmdNewJobp3" and "cmdDeleteJobp3" command buttons on the form.
These buttons do as I intend except that I would like the combo box list to
update. After adding a new record the record does not show up in the list
even though the record count on the Navigation buttons at the bottom of the
form inceases and I can to to the new record. When a record is deleted, it
still shows up in the combe list as "#Deleted" and the Navagation record
count reduces by one. If I select the combo "#deleted" record I get an Access
Error. If I close the form and reopen the form, everything is in order. What
else do I need to do? The code behind these controsl is as follows:

Private Sub cmdNewJobp3_Click()
Dim db As Database
Dim rs As Recordset

On Error GoTo Err_cmdNewJobp3_Click


DoCmd.GoToRecord , , acNewRec
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblJobs")
rs.Edit
rs.Update
rs.Close

Exit_cmdNewJobp3_Click:
Exit Sub

Err_cmdNewJobp3_Click:
MsgBox Err.Description
Resume Exit_cmdNewJobp3_Click

End Sub

Private Sub cmdDeleteJobp3_Click()
On Error GoTo Err_cmdDeleteJobp3_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_cmdDeleteJobp3_Click:
Exit Sub

Err_cmdDeleteJobp3_Click:
MsgBox Err.Description
Resume Exit_cmdDeleteJobp3_Click

End Sub
Private Sub cboJobName1_AfterUpdate()
Dim rs As Recordset, Criteria

Set rs = Me.RecordsetClone
Criteria = "[JobID] = " & Me.cboJobName1
rs.FindFirst Criteria
If Not rs.NoMatch = True Then
Me.Bookmark = rs.Bookmark
End If

End Sub
 
R

roadie.girl

Put me.Requery in the correct function. It just tells access to refresh
the form. If that doesn't show it ... the other two commands that tell
the screen to redraw are ...
Me.Repaint
Me.Refresh

Private Sub cboJobName1_AfterUpdate()
Dim rs As Recordset, Criteria


Set rs = Me.RecordsetClone
Criteria = "[JobID] = " & Me.cboJobName1
rs.FindFirst Criteria
If Not rs.NoMatch = True Then
Me.Bookmark = rs.Bookmark
End If

Me.Requery

End Sub

hth
 
G

Guest

As the last line in your Delete command button:
Me.cmboJobNamep3.Requery

Also put the same line in the AfterInsert Event of the Form so it will
requery to include the new record.
 

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