Refresh / requery form called from button on main form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a main form (called "mine" at present) containing library details,
with several subforms (eg "subfrmHOURS", detailing opening hours for the
particular library) that are opened from the main form with the record
corresponding to the library that was displayed on the main form. The link is
the library ID, present in both library and HOURS table. This was set up
using the Form Wizard.

When I move from the library displayed on the main form, ideally the subform
should change its details to match the main form details. I have a DLookup in
the header that displays the name of the library, and this is refreshed from
a button on the subform that calls Form.Refresh. The data in the Detail
section, however, is not refreshed: it still displays details for the
previous library.

I have tried Forms!subfrmLOANS.Requery
in the Form_Activate method of the main form, results in a message that the
database can't find the subfrmLOANS .

I have tried
Private Sub cmdRefreshLoans_Click()
Form.Refresh

Form.Requery
End Sub
which has no effect on the detail.

Refresh on the Records toolbar does not change the detail either, so it
looks like Requery may be the answer.

But how? and where?

Thanks.
 
Thanks for your reply. I tried the following in the On Click method of a
button attached to the subfrmLOANS form:

Private Sub cmdRefreshLoans_Click()
Form.Refresh

Me.subfrmLOANS.Requery
End Sub

with the following message box after changing the record in the library main
form, selecting the subformLOANS form, and clicking the cmdRefreshLoans
button:

---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Method or data member not found
---------------------------
OK Help
---------------------------

Should the Requery call be elsewhere?

I really appreciate your help. Thanks!

Ofer said:
Try

Me.[Enter here the sub form control name in the main form].Requery

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



kasab said:
I have a main form (called "mine" at present) containing library details,
with several subforms (eg "subfrmHOURS", detailing opening hours for the
particular library) that are opened from the main form with the record
corresponding to the library that was displayed on the main form. The link is
the library ID, present in both library and HOURS table. This was set up
using the Form Wizard.

When I move from the library displayed on the main form, ideally the subform
should change its details to match the main form details. I have a DLookup in
the header that displays the name of the library, and this is refreshed from
a button on the subform that calls Form.Refresh. The data in the Detail
section, however, is not refreshed: it still displays details for the
previous library.

I have tried Forms!subfrmLOANS.Requery
in the Form_Activate method of the main form, results in a message that the
database can't find the subfrmLOANS .

I have tried
Private Sub cmdRefreshLoans_Click()
Form.Refresh

Form.Requery
End Sub
which has no effect on the detail.

Refresh on the Records toolbar does not change the detail either, so it
looks like Requery may be the answer.

But how? and where?

Thanks.
 
Is the subfrmLOANS name of the sub form, or the sub form frame within the
main form (need to be the frame)

Where is the button?

Try this
Forms![MainFormName]![SubFormFrameNameInMainForm].Requery
Or
Forms![MainFormName]![SubFormFrameNameInMainForm].Form.Requery

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



kasab said:
Thanks for your reply. I tried the following in the On Click method of a
button attached to the subfrmLOANS form:

Private Sub cmdRefreshLoans_Click()
Form.Refresh

Me.subfrmLOANS.Requery
End Sub

with the following message box after changing the record in the library main
form, selecting the subformLOANS form, and clicking the cmdRefreshLoans
button:

---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Method or data member not found
---------------------------
OK Help
---------------------------

Should the Requery call be elsewhere?

I really appreciate your help. Thanks!

Ofer said:
Try

Me.[Enter here the sub form control name in the main form].Requery

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



kasab said:
I have a main form (called "mine" at present) containing library details,
with several subforms (eg "subfrmHOURS", detailing opening hours for the
particular library) that are opened from the main form with the record
corresponding to the library that was displayed on the main form. The link is
the library ID, present in both library and HOURS table. This was set up
using the Form Wizard.

When I move from the library displayed on the main form, ideally the subform
should change its details to match the main form details. I have a DLookup in
the header that displays the name of the library, and this is refreshed from
a button on the subform that calls Form.Refresh. The data in the Detail
section, however, is not refreshed: it still displays details for the
previous library.

I have tried Forms!subfrmLOANS.Requery
in the Form_Activate method of the main form, results in a message that the
database can't find the subfrmLOANS .

I have tried
Private Sub cmdRefreshLoans_Click()
Form.Refresh

Form.Requery
End Sub
which has no effect on the detail.

Refresh on the Records toolbar does not change the detail either, so it
looks like Requery may be the answer.

But how? and where?

Thanks.
 
Not sure if its the name of a subform. I was wrong, The link between the 2
was created using the Button Wizard. The button is on form "mine",
"subfrmLOANS" opens to record corresponding with record open in "mine" form.
Access seems to call forms similar to "subfrmLOANS" a subform, but there is
no frame on the "mine" form, just the button.

Is it really a subform, or a form?

Both of the commands below produced the error :

Run-time error '2465':

Toy Libraries Victoria Membership Database can't find the field
'subfrmLOANS' referred to in your expression.

Thank you for your patience.


Ofer said:
Is the subfrmLOANS name of the sub form, or the sub form frame within the
main form (need to be the frame)

Where is the button?

Try this
Forms![MainFormName]![SubFormFrameNameInMainForm].Requery
Or
Forms![MainFormName]![SubFormFrameNameInMainForm].Form.Requery

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



kasab said:
Thanks for your reply. I tried the following in the On Click method of a
button attached to the subfrmLOANS form:

Private Sub cmdRefreshLoans_Click()
Form.Refresh

Me.subfrmLOANS.Requery
End Sub

with the following message box after changing the record in the library main
form, selecting the subformLOANS form, and clicking the cmdRefreshLoans
button:

---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Method or data member not found
---------------------------
OK Help
---------------------------

Should the Requery call be elsewhere?

I really appreciate your help. Thanks!

Ofer said:
Try

Me.[Enter here the sub form control name in the main form].Requery

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



:

I have a main form (called "mine" at present) containing library details,
with several subforms (eg "subfrmHOURS", detailing opening hours for the
particular library) that are opened from the main form with the record
corresponding to the library that was displayed on the main form. The link is
the library ID, present in both library and HOURS table. This was set up
using the Form Wizard.

When I move from the library displayed on the main form, ideally the subform
should change its details to match the main form details. I have a DLookup in
the header that displays the name of the library, and this is refreshed from
a button on the subform that calls Form.Refresh. The data in the Detail
section, however, is not refreshed: it still displays details for the
previous library.

I have tried Forms!subfrmLOANS.Requery
in the Form_Activate method of the main form, results in a message that the
database can't find the subfrmLOANS .

I have tried
Private Sub cmdRefreshLoans_Click()
Form.Refresh

Form.Requery
End Sub
which has no effect on the detail.

Refresh on the Records toolbar does not change the detail either, so it
looks like Requery may be the answer.

But how? and where?

Thanks.
 
Sounds to me as if you have something fundamentally wrong in the setup.

Question 1: Could you post the click code of the button you're using?
Question 2: Do you want the hours to open as a separate form, or as an
integral part of the main form?


kasab said:
Not sure if its the name of a subform. I was wrong, The link between the 2
was created using the Button Wizard. The button is on form "mine",
"subfrmLOANS" opens to record corresponding with record open in "mine" form.
Access seems to call forms similar to "subfrmLOANS" a subform, but there is
no frame on the "mine" form, just the button.

Is it really a subform, or a form?

Both of the commands below produced the error :

Run-time error '2465':

Toy Libraries Victoria Membership Database can't find the field
'subfrmLOANS' referred to in your expression.

Thank you for your patience.


Ofer said:
Is the subfrmLOANS name of the sub form, or the sub form frame within the
main form (need to be the frame)

Where is the button?

Try this
Forms![MainFormName]![SubFormFrameNameInMainForm].Requery
Or
Forms![MainFormName]![SubFormFrameNameInMainForm].Form.Requery

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



kasab said:
Thanks for your reply. I tried the following in the On Click method of a
button attached to the subfrmLOANS form:

Private Sub cmdRefreshLoans_Click()
Form.Refresh

Me.subfrmLOANS.Requery
End Sub

with the following message box after changing the record in the library main
form, selecting the subformLOANS form, and clicking the cmdRefreshLoans
button:

---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Method or data member not found
---------------------------
OK Help
---------------------------

Should the Requery call be elsewhere?

I really appreciate your help. Thanks!

:

Try

Me.[Enter here the sub form control name in the main form].Requery

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



:

I have a main form (called "mine" at present) containing library details,
with several subforms (eg "subfrmHOURS", detailing opening hours for the
particular library) that are opened from the main form with the record
corresponding to the library that was displayed on the main form. The link is
the library ID, present in both library and HOURS table. This was set up
using the Form Wizard.

When I move from the library displayed on the main form, ideally the subform
should change its details to match the main form details. I have a DLookup in
the header that displays the name of the library, and this is refreshed from
a button on the subform that calls Form.Refresh. The data in the Detail
section, however, is not refreshed: it still displays details for the
previous library.

I have tried Forms!subfrmLOANS.Requery
in the Form_Activate method of the main form, results in a message that the
database can't find the subfrmLOANS .

I have tried
Private Sub cmdRefreshLoans_Click()
Form.Refresh

Form.Requery
End Sub
which has no effect on the detail.

Refresh on the Records toolbar does not change the detail either, so it
looks like Requery may be the answer.

But how? and where?

Thanks.
 
Re Question 1:
The code to open the "subfrmLOANS" form is

Private Sub cmdOpenLoans1_Click()
On Error GoTo Err_cmdOpenLoans1_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "subfrmLOANS"

stLinkCriteria = "[TLid]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenLoans1_Click:
Exit Sub

Err_cmdOpenLoans1_Click:
MsgBox Err.Description
Resume Exit_cmdOpenLoans1_Click

End Sub

attached to a button on the main form ("mine").

The code to refresh the "subfrmLOANS" form is:

Private Sub cmdRefreshLoans_Click()
Form.Refresh
End Sub

At various stages I have used

Forms![mine]![subfrmLOANS].Requery
Or
Forms![mine]![subfrmLOANS].Form.Requery

inside the cmdRefreshLoans_Click() sub, with error = couldn't find
subfrmLOANS.
The Refresh command does, however, refresh the library name (if the record
in "mine" has changed) that I have put in a text box in the subfrmLOANS
header using a DLookup to the table used on the main form ("mine"), but the
detail is not refreshed or requeried

Re: Question 2:
Yes, ideally, "subforms" should open as separate forms for clarity. There
are a lot of details in many tables in the database, and the form is used for
checking registration of library members each year. Tabbed forms or 1 huge,
long set of subforms in frames(?) on the main form just got unworkable. Too
many mistakes were added in the data. Also, all forms should be useful for
editing (which I have enabled, and has been tested).

So the question is: how is it possible to requery synchronised forms opened
from a main form?, or to keep both in synch when opened?

Thanks.

Rob Oldfield said:
Sounds to me as if you have something fundamentally wrong in the setup.

Question 1: Could you post the click code of the button you're using?
Question 2: Do you want the hours to open as a separate form, or as an
integral part of the main form?


kasab said:
Not sure if its the name of a subform. I was wrong, The link between the 2
was created using the Button Wizard. The button is on form "mine",
"subfrmLOANS" opens to record corresponding with record open in "mine" form.
Access seems to call forms similar to "subfrmLOANS" a subform, but there is
no frame on the "mine" form, just the button.

Is it really a subform, or a form?

Both of the commands below produced the error :

Run-time error '2465':

Toy Libraries Victoria Membership Database can't find the field
'subfrmLOANS' referred to in your expression.

Thank you for your patience.


Ofer said:
Is the subfrmLOANS name of the sub form, or the sub form frame within the
main form (need to be the frame)

Where is the button?

Try this
Forms![MainFormName]![SubFormFrameNameInMainForm].Requery
Or
Forms![MainFormName]![SubFormFrameNameInMainForm].Form.Requery

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



:

Thanks for your reply. I tried the following in the On Click method of a
button attached to the subfrmLOANS form:

Private Sub cmdRefreshLoans_Click()
Form.Refresh

Me.subfrmLOANS.Requery
End Sub

with the following message box after changing the record in the library main
form, selecting the subformLOANS form, and clicking the cmdRefreshLoans
button:

---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Method or data member not found
---------------------------
OK Help
---------------------------

Should the Requery call be elsewhere?

I really appreciate your help. Thanks!

:

Try

Me.[Enter here the sub form control name in the main form].Requery

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



:

I have a main form (called "mine" at present) containing library details,
with several subforms (eg "subfrmHOURS", detailing opening hours for the
particular library) that are opened from the main form with the record
corresponding to the library that was displayed on the main form. The link is
the library ID, present in both library and HOURS table. This was set up
using the Form Wizard.

When I move from the library displayed on the main form, ideally the subform
should change its details to match the main form details. I have a DLookup in
the header that displays the name of the library, and this is refreshed from
a button on the subform that calls Form.Refresh. The data in the Detail
section, however, is not refreshed: it still displays details for the
previous library.

I have tried Forms!subfrmLOANS.Requery
in the Form_Activate method of the main form, results in a message that the
database can't find the subfrmLOANS .

I have tried
Private Sub cmdRefreshLoans_Click()
Form.Refresh

Form.Requery
End Sub
which has no effect on the detail.

Refresh on the Records toolbar does not change the detail either, so it
looks like Requery may be the answer.

But how? and where?

Thanks.
 
Thank you both very much for your responses.

Figured it out, hadn't thought to search Access help for "synchronize"
before. I'll summarise the answer so others who haven't done this before can
see what can be done.

You can synchronise open forms using the On Current event, with the
following code (amended from Microsoft Access Help) that you attach to the
main form:

Private Sub Form_Current()
' Declare and set a variable to store the WHERE
' clause that describes the records you want to
' display.
Dim strCond As String
strCond = "[Linking field in form you want to change] = Forms![Form
initiating the response]![Linking field in the form initiating the change]"

' Use the IsLoaded function from the Northwind
' sample database to check whether the Products
' form is open, then set the properties.

If IsLoaded("subfrmHOURS") Then
Forms![subfrmHOURS].FilterOn = True
Forms![subfrmHOURS].Filter = strCond
Forms![subfrmHOURS].Refresh
End If

End Sub

The Northwind sample database is likely to be installed into C:\Program _
Files\Microsoft Office\OFFICE11\SAMPLES folder during installation of
Office 2003. The IsLoaded function is one of the Northwind database
Utility modules. Copy this to the end of your code, not the modules section.
You won't need to edit this function at all.

Access Help has an entry entitled "About synchronizing records between two
forms" and another "Examples of synchronizing two forms programmatically" -
both are very useful.

kasab said:
Re Question 1:
The code to open the "subfrmLOANS" form is

Private Sub cmdOpenLoans1_Click()
On Error GoTo Err_cmdOpenLoans1_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "subfrmLOANS"

stLinkCriteria = "[TLid]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenLoans1_Click:
Exit Sub

Err_cmdOpenLoans1_Click:
MsgBox Err.Description
Resume Exit_cmdOpenLoans1_Click

End Sub

attached to a button on the main form ("mine").

The code to refresh the "subfrmLOANS" form is:

Private Sub cmdRefreshLoans_Click()
Form.Refresh
End Sub

At various stages I have used

Forms![mine]![subfrmLOANS].Requery
Or
Forms![mine]![subfrmLOANS].Form.Requery

inside the cmdRefreshLoans_Click() sub, with error = couldn't find
subfrmLOANS.
The Refresh command does, however, refresh the library name (if the record
in "mine" has changed) that I have put in a text box in the subfrmLOANS
header using a DLookup to the table used on the main form ("mine"), but the
detail is not refreshed or requeried

Re: Question 2:
Yes, ideally, "subforms" should open as separate forms for clarity. There
are a lot of details in many tables in the database, and the form is used for
checking registration of library members each year. Tabbed forms or 1 huge,
long set of subforms in frames(?) on the main form just got unworkable. Too
many mistakes were added in the data. Also, all forms should be useful for
editing (which I have enabled, and has been tested).

So the question is: how is it possible to requery synchronised forms opened
from a main form?, or to keep both in synch when opened?

Thanks.

Rob Oldfield said:
Sounds to me as if you have something fundamentally wrong in the setup.

Question 1: Could you post the click code of the button you're using?
Question 2: Do you want the hours to open as a separate form, or as an
integral part of the main form?


kasab said:
Not sure if its the name of a subform. I was wrong, The link between the 2
was created using the Button Wizard. The button is on form "mine",
"subfrmLOANS" opens to record corresponding with record open in "mine" form.
Access seems to call forms similar to "subfrmLOANS" a subform, but there is
no frame on the "mine" form, just the button.

Is it really a subform, or a form?

Both of the commands below produced the error :

Run-time error '2465':

Toy Libraries Victoria Membership Database can't find the field
'subfrmLOANS' referred to in your expression.

Thank you for your patience.


:

Is the subfrmLOANS name of the sub form, or the sub form frame within the
main form (need to be the frame)

Where is the button?

Try this
Forms![MainFormName]![SubFormFrameNameInMainForm].Requery
Or
Forms![MainFormName]![SubFormFrameNameInMainForm].Form.Requery

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



:

Thanks for your reply. I tried the following in the On Click method of a
button attached to the subfrmLOANS form:

Private Sub cmdRefreshLoans_Click()
Form.Refresh

Me.subfrmLOANS.Requery
End Sub

with the following message box after changing the record in the library main
form, selecting the subformLOANS form, and clicking the cmdRefreshLoans
button:

---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Method or data member not found
---------------------------
OK Help
---------------------------

Should the Requery call be elsewhere?

I really appreciate your help. Thanks!

:

Try

Me.[Enter here the sub form control name in the main form].Requery

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



:

I have a main form (called "mine" at present) containing library details,
with several subforms (eg "subfrmHOURS", detailing opening hours for the
particular library) that are opened from the main form with the record
corresponding to the library that was displayed on the main form. The link is
the library ID, present in both library and HOURS table. This was set up
using the Form Wizard.

When I move from the library displayed on the main form, ideally the subform
should change its details to match the main form details. I have a DLookup in
the header that displays the name of the library, and this is refreshed from
a button on the subform that calls Form.Refresh. The data in the Detail
section, however, is not refreshed: it still displays details for the
previous library.

I have tried Forms!subfrmLOANS.Requery
in the Form_Activate method of the main form, results in a message that the
database can't find the subfrmLOANS .

I have tried
Private Sub cmdRefreshLoans_Click()
Form.Refresh

Form.Requery
End Sub
which has no effect on the detail.

Refresh on the Records toolbar does not change the detail either, so it
looks like Requery may be the answer.

But how? and where?

Thanks.
 
Glad you got it sorted out. For reference, the IsLoaded function in
Northwind is slightly outdated. There is now (A2K and later I believe) an
IsLoaded property on a form. e.g.

if CurrentProject.AllForms("FormName").IsLoaded then
 

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

Back
Top