Refresh/ Requery

J

JenK

I have a delivery slip form, I have a button that when clicked opens the
project form to edit or enter a new project. What I would like to have happen
is that when the form is closed the project combo box is updated with the new
information.
This project form button is on a few other forms (PO & Timesheets). I would
like the refresh/requery to work on all the forms (depending on which one I
open it from).
The button is running from VBA coding.
 
G

Golfinray

Forms automatically save entered data to the source table or query. If
necessary, put a save command button on the form.
 
J

JenK

I have had a save button, but the combo list field is not automatically
updated still.
I was wondering if there was some sort of code that said requery open forms.
 
P

Paul Shapiro

It's not as simple as that. You have to write code to requery any affected
combo boxes. Access only queries the rowsource once, when it opens the form,
to save what would usually be wasted processing. After that you have to tell
it when to requery.

You could run code something like this (sytax will need fixing):
For Each frm In Access.Forms
If frm.controls("cboProject") Then
frm.cboProject.Requery
End If
Next frm

That would depend on you naming all of the project combo boxes with the same
name. You could also add a method to ALL your forms, something like this:
Public Sub RequeryAffectedComboBoxes(strBaseTableName as String)
Select Case strBaseTableName
Case "Project"
Then Me.cboProject.Requery
End Select
End Sub

Each form only needs to support the base table names it cares about.

Then in the form where you're changing the projects, you would replace the
earlier code with:
For Each frm In Access.Forms
Call frm.RequeryAffectedComboBoxes(strBaseTableName:="Project")
Next frm
 

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