Discussion Locked

Access - Refreshing Combo Boxes

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a sub-form with a combo box that requires a choice from a contacts table. If a contact doesn't exist, then I have a "new contact" button that opens up the contact form to enter a new contact. Once you have entered the new contact and closedthe contact form you return to the subform. However, the drop down combo box doesn't reflect the new entry....

If you exit the original form and reopen it then the new entry is reflected, but that is not acceptable.

How do I force the drop-down list to "refresh" after I return from entering a new contact?

7 replies

by kiwimac

Hi OfficeGuy

I had a similuar problem, this is how I got around it

First you need to create a function in the Module tab and add the following code to it.
Now add the following code to the On Click event of the button that closes your Contract form

Code for Function

Public Function IsOpen(ByVal strFormName As String) As Boolean
'Returns True if the specified form is open in Form view.

Const conDesignView = 0
Const conObjStateClosed = 0

IsOpen = False If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsOpen = True
End If
End If

End Function

Code for Form

PrivateSub cmdClose_Click()
On Error GoTo Err_cmdClose_Click

If IsOpen("frmContracts") Then ' Change these to match your form names
Forms!frmContracts.Refresh
End If

If IsOpen("frmDetails") Then ' Change these to match your form names
Forms![frmDetails].Refresh
End If

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click

End Sub

If this doesn't do the trick then try the next option.

On Enter event for the subform add the following bit of code

DoCmd.Requery "tblContracts"

where tblContracts is the name of the table youare updating.

Hope these help.
Craig

by donq

Keep it simple!!!

Build a simple query to deliver exactly what you want and after checking it switch to SEL view and copy it to the clipboard [Ctrl]+C.

Open your subform in design view and double click on your Combo box to open its properties sheet. Do a paste [Ctrl]+V from the clipboard into the "Row Source" property and your combo box will run the query each time it is clicked to ALWAYS deliver 100% of presaved values.

It's like a requery only simpler?

Good Luck - Don Quigg

by officeguy

Very helpful trick, but I got an easier answer that only performed the "refresh" upon exiting the "add contact form"

by it_cowboy

all you need to do is requery to combo box in the close event of the contact form.
If the form name containing the combo box is called 'Main',
Enter in the 'On Close' event for the 'Contact' Form

Forms!Main!ComboBox.Requery

As the combo box only needs refreshing when you add a contact to the contact form, tie the requery event to the contact form. much more efficient and only one line of code!

This discussion is closed to new replies.