Requery a form that is already open in Access 2003

I have a main form that I have put a VB control on to go to open up another form with has password to open it in the open form event. If I put Docmd.close on this cmd button it closes the form before the other form opens. If the user does not put the right password in the current form is also closed.

What I am looking to do is when I am in the second form that required the password and i click on the cmd button to clsoe that form it will requery the original form
PdetersAsked:
Who is Participating?
 
aesmikeConnect With a Mentor Commented:
The approach I'm thinking of is this:
From the hospital form, user clicks a button to launch the 2nd form.  The onClick event of Hospital form opens the 2nd form modally (e.g. docmd.OpenForm "blah blah",,,,,acDialog)
When you do this, the code in the hospital form stops at the OpenForm line and waits until the 2nd form is closed.  Now, the code in the hospital form continues to the next line which would refresh the hospital name.  You shouldn't have to close the hospital form and reopen just because you want to see the new name.  If you do, then we have to talk about how your hospital name is displayed and come up with the answer to that.
0
 
aesmikeCommented:
Forms!OriginalForm.requery
0
 
PdetersAuthor Commented:
Where should I put this. I put it in the event of the cmd button to close the 2nd form
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
aesmikeCommented:
Explain the flow of how you want it to work a little more.  Sounds like you have a main form and a 2nd form.  The 2nd form is password protected.  You have a button on the main form that opens the 2nd form.  If the 2nd form opens successfully, what happens to the main form?  stays open or gets closed?
Eventually the 2nd form gets closed.  There's a button on this 2nd form to close it?  If 2nd form closes, it sounds like you want the main form to be requeried.  If that's the case, I assume the main form is to remain open all the time.  That being the case, put the Requery command in the OnClose event of the 2nd form.  That way it fires off if the user clicks the button or clicks the "X" at top right.
In any event, before requerying the main form you should check to make sure it's still open (a user could close it accidentally)
0
 
PdetersAuthor Commented:
I also have some combo boxes that you can select the record that you want .

0
 
PdetersAuthor Commented:
What code could i put in the 2nd form to close and then reopen the first form
0
 
aesmikeCommented:
what's the intent behind closing and reopening the first form?  (other than to requery it if it's already open)
0
 
PdetersAuthor Commented:
It doesn't seem to be requery - I have a combo box that you select the record you want. This is not requeying
0
 
aesmikeCommented:
I don't mean to sound dense, but can you explain , from the top, how you would like your application to work (e.g. "I click here and this happens, I close this and this should happen, etc")
0
 
PdetersAuthor Commented:
Not a problem and you are not the dense one - (That would be me)

This is what I am looking for
My main form "HospitalForm" - the name of the hospital is locked on the form so it does not accidentally get changed - so for the main user to be able to change it I created a form that she could go to to be able to change the name and address of the hospital - they want no one else to have access to this so I created a form that required a password to open. - i put the code in the "OnOpen" event in the subform.

So after the informaiton is updated in the subform I would like to be able to go back to the main form and have it updated there - If I just requery the drop downs that are used to choose a record are not changed until you close and reopen the form.

If I put a Docmd.Close on the command button that goes to the subform it closes before the person has to put in the password and then if they put in the wrong password they are not in any form any longer but but back to a Switchboard. I would like if possible that if they are not able to put in the correct password to the subform that they remain in the main form.

Am I making sense??
0
 
aesmikeCommented:
Ok, makes more senese, however the part you left out is that you are closing the main form somewhere.  Is the reason you are closing the main form is to get this combo box to show the correct value?

2nd question: Can the 2nd form be opened Modally, as a dialog box?
3rd Question: The hospital name is displayed in a combo box on the hospital form, correct?  A user can change this to another hospital but they can't change the actual name of the currently displayed hospital unless they go into this 2nd form, correct?
4th question: The combo box that displays the names of hospitals, is there some hospital id or something other than the name that's a key field?
0
 
PdetersAuthor Commented:
Questions
1- Yes - I am wanting to refresh
2 - Sorry but am not really sure what you mean by second qeustions.
3 - Yes hospital name is displayed in combo box to choose hospital - correct - they can change to another hospital but can not change the name of the hospital
4 - the key fieild is an id field - is in the combo box bu they do not see it
You approach sounds like exactly what I am looking for. Right now I have a button that launches the 2nd form - this is the code on the on click event of the button

Private Sub cmdChangeHospital_Click()
On Error GoTo Err_cmdChangeHospital_Click
    Dim stDocName As String
    Dim stLinkCriteria As String

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

Exit_cmdChangeHospital_Click:
    Exit Sub

Err_cmdChangeHospital_Click:
    MsgBox Err.Description
    Resume Exit_cmdChangeHospital_Click
   
End Sub
0
 
PdetersAuthor Commented:
Sorry it took me so long to get back to this. Thanks!!

Patty
0
 
aesmikeCommented:
you're welcome.  So it worked?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.