Link to home
Start Free TrialLog in
Avatar of Pdeters
Pdeters

asked on

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
Avatar of aesmike
aesmike

Forms!OriginalForm.requery
Avatar of Pdeters

ASKER

Where should I put this. I put it in the event of the cmd button to close the 2nd form
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)
Avatar of Pdeters

ASKER

I also have some combo boxes that you can select the record that you want .

Avatar of Pdeters

ASKER

What code could i put in the 2nd form to close and then reopen the first form
what's the intent behind closing and reopening the first form?  (other than to requery it if it's already open)
Avatar of Pdeters

ASKER

It doesn't seem to be requery - I have a combo box that you select the record you want. This is not requeying
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")
Avatar of Pdeters

ASKER

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??
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?
ASKER CERTIFIED SOLUTION
Avatar of aesmike
aesmike

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pdeters

ASKER

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
Avatar of Pdeters

ASKER

Sorry it took me so long to get back to this. Thanks!!

Patty
you're welcome.  So it worked?