Requerying a control...

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

Guest

Hello,
I have a form that holds the names of Doctors and their contact information.
This form pulls from a doctor table.
This form is embedded in a doctor visit form, of which I have an 'edit
doctor details' button. This button opens up the form 'doctors' and allows
the user to edit the doctor information.
My challenge is that I am using a requery to update the changes (Code below)
on the Onclose property of the form. I picked this up from this forum with
respect to another challenge I was facing with another form.

Dim MyControl As Control
Set MyControl =
Forms![frmclients][frmdoctorvisit]![tblJunctionDoctorsandClients
Subform]![Name]
MyControl.Requery

As you can see, it only updates the name. Is there a way I can update any
field in the doctors table (address, phone, etc) and have it immediately
requery any changes that have been made on the fly without having to load the
form again? I tried removing [Name] from the statement; no joy.

Thanks in advance,

Rookie.
 
You can requery a form (or subform), not just a control on it.
Something like this, perhaps?

Forms![frmclients][frmdoctorvisit]![tblJunctionDoctorsandClientsSubform].For
m.Requery
 
I used "Forms![frmclients][frmdoctorvisit]![tblJunctionDoctorsandClients
Subform]![Name]" to try and decipher your post.

My understanding is that you have a main form called frmdoctorvisit?
You have an embedded subform in frmdoctorvisit called
tblJunctionDoctorsAndClientsSubform?
You have a command button which then opens up another form so that you can
edit the information?
(I have no idea where frmclients comes from.)
Once you close this form, you want it to update your main form without
having to close and reopen the main form?
If so, try this code under the On Close event:

Form_frmdoctorvisit.SetFocus
Form_frmdoctorvisit![tblJunctionDoctorsAndClientsSubform].Form.Requery
 
Hey guys,

Thanks for your your posts.

Your right...I have a subform called tblJunctionDoctorsAndClientsSubform
embedded in a form called frmdoctorvisit. And yes, I have a command button
that opens up the doctor info in a form. The frmclients is the main
form...frmdoctorvisit is an embedded subform on one of the tabs.
This is what I have on the onClose event of the Doctors form:

Private Sub Form_Close()
Form_frmdoctorvisit.SetFocus
Form_frmdoctorvisit![tablJunctionDoctorsandClientsSubform].Form.Requery
End Sub

It gave me a syntax error, saying variable not defined.

Out of ideas and grateful for any,

John.
 
It gave me a syntax error, saying variable not defined.

Try a bit different syntax:

Private Sub Form_Close()
Forms!frmdoctorvisit.SetFocus
Forms!frmdoctorvisit![tablJunctionDoctorsandClientsSubform].Form.Requery
End Sub


John W. Vinson[MVP]
 
Hey John,

Thanks for your reply: it works, but with an error message: it can't find my
frmdoctorvisit. When I click End instead of debug, it updates.

What should the setfocus command point to?
Here's my setup: I have a frmdoctorvisit embedded in frmclients, and a
tblJunctionDoctorsandClients Subform embedded in frmdoctorvisit.
My 'Edit Doctor' command button brings up my frmdoctors. It's the OnClose
property on my frmDoctors that has the code below:

Private Sub Form_Close()
Form!frmdoctorvisit.SetFocus
Form!frmdoctorvisit![tblJunctionDoctorsandClientsSubform].Form.Requery
End Sub

Thanks again,

John.

John Vinson said:
It gave me a syntax error, saying variable not defined.

Try a bit different syntax:

Private Sub Form_Close()
Forms!frmdoctorvisit.SetFocus
Forms!frmdoctorvisit![tablJunctionDoctorsandClientsSubform].Form.Requery
End Sub


John W. Vinson[MVP]
 
Thanks for your reply: it works, but with an error message: it can't find my
frmdoctorvisit. When I click End instead of debug, it updates.

What should the setfocus command point to?
Here's my setup: I have a frmdoctorvisit embedded in frmclients, and a
tblJunctionDoctorsandClients Subform embedded in frmdoctorvisit.

If the master form is frmClients, you'll need to navigate to the
subforms through it:

Forms!frmClients!frmDoctorVisit.Form

is the first subform;

Forms!frmClients!frmDoctorVisit.Form![tblJunctionDoctorsAndClients
Subform].Form

is the nested subform.

This assumes that the name property of the Subform control - the
relevant name for this purpose - is the same as the name of the form
within that control. That's the Access default but it's not required.

John W. Vinson[MVP]
 
I note that your code is using
Form!...
where John Vinson's uses
Forms!

The difference is significant.
As are his comments on syntax.

Access rookie said:
Hey John,

Thanks for your reply: it works, but with an error message: it can't find my
frmdoctorvisit. When I click End instead of debug, it updates.

What should the setfocus command point to?
Here's my setup: I have a frmdoctorvisit embedded in frmclients, and a
tblJunctionDoctorsandClients Subform embedded in frmdoctorvisit.
My 'Edit Doctor' command button brings up my frmdoctors. It's the OnClose
property on my frmDoctors that has the code below:

Private Sub Form_Close()
Form!frmdoctorvisit.SetFocus
Form!frmdoctorvisit![tblJunctionDoctorsandClientsSubform].Form.Requery
End Sub

Thanks again,

John.

John Vinson said:
It gave me a syntax error, saying variable not defined.

Try a bit different syntax:

Private Sub Form_Close()
Forms!frmdoctorvisit.SetFocus
Forms!frmdoctorvisit![tablJunctionDoctorsandClientsSubform].Form.Requery
End Sub


John W. Vinson[MVP]
 
Hey guys,

Thank you so much! It works...I am amazed at how a space in a statement can
mess the whole thing up.

Happy rest of the week,

John.

MacDermott said:
I note that your code is using
Form!...
where John Vinson's uses
Forms!

The difference is significant.
As are his comments on syntax.

Access rookie said:
Hey John,

Thanks for your reply: it works, but with an error message: it can't find my
frmdoctorvisit. When I click End instead of debug, it updates.

What should the setfocus command point to?
Here's my setup: I have a frmdoctorvisit embedded in frmclients, and a
tblJunctionDoctorsandClients Subform embedded in frmdoctorvisit.
My 'Edit Doctor' command button brings up my frmdoctors. It's the OnClose
property on my frmDoctors that has the code below:

Private Sub Form_Close()
Form!frmdoctorvisit.SetFocus
Form!frmdoctorvisit![tblJunctionDoctorsandClientsSubform].Form.Requery
End Sub

Thanks again,

John.

John Vinson said:
On Mon, 7 Feb 2005 17:15:04 -0800, "Access rookie"

It gave me a syntax error, saying variable not defined.


Try a bit different syntax:

Private Sub Form_Close()
Forms!frmdoctorvisit.SetFocus
Forms!frmdoctorvisit![tablJunctionDoctorsandClientsSubform].Form.Requery
End Sub


John W. Vinson[MVP]
 
Back
Top