Combo Box values are not updated untill the form is closed/reopene

M

Mishanya

The Combo Box in the ClientDetails form is based on value list from the
table ClientName. Whenever a data for a new client has to be input in the
form, button "Add New Client" have to be pressed (it opens the form, wich
adds new clients to the ClientName table).
But after adding a new name, closing the "Add New Client" form and opening
the Combo Box in the ClientDetails form (wich is still open),no new names
appear in it untill the form is closed and reopened.
What has to be done?
 
L

Linq Adams via AccessMonster.com

In the code for your "Add New Client" button, you need to open your second
form in Modal, then add a line after opening the form that requeries the
combobox:

DoCmd.OpenForm "YourSecondFormName", , , , , acDialog
Me.ComboBoxName.Requery
 
M

Mishanya

I'm sorry but I didn't quite understand.

I Have 2 tables: tblClientName and tblClientDetails in which the field
ClientName is ComboBox based on the tblClientName.
I have 2 forms: frmClientDetails (based on tblClientName) and frmClientName
(based on the tblClientName).

So the ClientName field in the frmClientDetails is presented as ComboBox
(wich actually takes values from tblClientName and stores them in the
tblClientDetails).

The button, wich opens the frmClientName from frmClientDetails, has code:

Private Sub Open_Form_frmClientName_Click()
On Error GoTo Err_Open_Form_frmClientName_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmClientName"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Open_Form_frmClientName_Click:
Exit Sub

Err_Open_Form_frmClientName_Click:
MsgBox Err.Description
Resume Exit_Open_Form_frmClientName _Click

End Sub

After adding a new record to the frmClientName I just close it and stay with
already opened frmClientDetails.

Now, where do I put the addition U've mentioned (e.g. how exactly do I skin
this cat:)).
 
B

Beetle

You would modify your existing procedure as follows;

Private Sub Open_Form_frmClientName_Click()
On Error GoTo Err_Open_Form_frmClientName_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmClientName"
DoCmd.OpenForm strDocName, , , strLinkCriteria, , acDialog
Me![YourComboBox].Requery

Exit_Open_Form_frmClientName_Click:
Exit Sub

Err_Open_Form_frmClientName_Click:
MsgBox Err.Description
Resume Exit_Open_Form_frmClientName _Click

End Sub


Substitute the actual name of your combo box for YourComboBox.

When you open a form in Dialog mode (acDialog), all code halts until
that form is closed (or hidden). So when the users finish adding the
necessary information and close frmClientName, the next line of code
will resume which is to Reqeury the combo box.
 

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