Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to return to SAME record on Closing a Form 1

Status
Not open for further replies.

number2

Technical User
Oct 25, 2001
284
US
After opening a form via a button control from within a form, I need to return to the original record and form on using a close button.

In other words, on pressing a "close" button, I need to return to the original record and form.

I used the wizard close form button event below; that button event returns me to the First record in the set. I need to return to the record I was working on.

Private Sub Command33_Click()
On Error GoTo Err_Command33_Click


DoCmd.Close

Exit_Command33_Click:
Exit Sub

Err_Command33_Click:
MsgBox Err.Description
Resume Exit_Command33_Click

End Sub
 
interesting, well my first question is what key are you using on the form. Are yo using a invoiceno, custno. and at what stage did you last open the record you want to return to.

What I mean here is, say you are on form2 are you trying to return to form1 or are you tring to navigate back to a record in form2.

If say it is in form1. did you close form1 and open form2 straight away.

Or maybe you are trying to add a new job for your current customer and you want to keep certain details.

trying to visualize what it is you are trying to do.

Zero
 
Thanks for the help. Sorry I wasn't clear enough.

I am on main form1. I click a button to open form2 which is a form based on the record in view on form1.

On closing form2 either from a "close form" button or from the border control button I need to return back to the original record on form1, which is the record I was working on.

At present I am returned to the FIRST record not the record which was in view when moving to form2.
 
Try this, instead of closing the form hide it.

ON Form1:

Private Sub Command33_Click()
Visible = False
DoCmd.OpenForm "form2"
End Sub


ON form2:

Either on close of form2 or on click of a button add this.

DoCmd.SelectObject acForm, "form1"
DoCmd.Restore


** You will notice I have got rid of the error line in your code, you do not really need them, they are only good if you have tones of code and you want an onerror procedure.
All they do is take up space.

Hope this Helps

Zero :)
 
Thanks for the help. I am working with that now. Any way to Maximize the form when Restoring? Access 97 used to have a Maximize event, is that gone now??
 
Here's a problem; if the user closes form2 from the boder close button, form1 will not reappear. I could do away with the border I suppose. but...
 
Hiding the form does not seem to work well. For one thing on restoring the form1 the form has odd resizing. There must be a way to call up the same record again from form 2 to stay with the original record.
 
hmm, ok the reason for restore is that it will resize your form to the correct size specified by your settings. Maximize is always an options and if that is what you want to do add this line instead.

DoCmd.Maximize
And if you want minimize
DoCmd.Minimize

Now as for the problem with the X close, get rid of it you will find out later on that it is a curse develop a close button on your form and do the following.

goto form properties
change control Box to NO

that should solve most of your problems

Zero
 
Thanks Zero. The Hinding and Restore does work, however I still get returned to the FIRST record. I don't understand it. Heres the code:
Button on form1 to open form2:

Private Sub Label290_Click()
Visible = False
Dim strCriteria As String
strCriteria = "[QME/AME Information]![lastname]=[Forms]![QME/AME Information]![lastname]"
DoCmd.OpenForm "Notification Form", acNormal, , strCriteria
DoCmd.Maximize
End Sub

Here is the close button (restore form1) on form2:

Private Sub Command49_Click()
DoCmd.Close
DoCmd.SelectObject acForm, "QME/AME Information"
DoCmd.Restore
DoCmd.Maximize
End Sub
 
Try this.

Button on form1 to open form2:

Dim stLinkCriteria As String
stLinkCriteria = "[Form2lastname]=" & Me![form1lastname]
DoCmd.Save acForm, "QME/AME Information"
Visible = False
DoCmd.OpenForm "Notification Form", , , stLinkCriteria
End Sub

I have a little problem with your link criteria, it does not look right. The link criteria is surpose to be a link between two forms where the details match. Yours looks like it is linking itself with itself??
it shoud look more like

stLinkCriteria = "[Form2lastname]=" & Me![form1lastname]

rather than:
strCriteria = "[QME/AME Information]![lastname]=[Forms]![QME/AME Information]![lastname]"


Here is the close button (restore form1) on form2:

Private Sub Command49_Click()
DoCmd.SetWarnings False
DoCmd.Close acForm, "Notification Form", acSaveYes
DoCmd.SelectObject acForm, "QME/AME Information"
DoCmd.Maximize
End Sub
 
Try this.

Button on form1 to open form2:

Dim stLinkCriteria As String
stLinkCriteria = "[Form2lastname]=" & Me![form1lastname]
DoCmd.Save acForm, "QME/AME Information"
Visible = False
DoCmd.OpenForm "Notification Form", , , stLinkCriteria
End Sub

I have a little problem with your link criteria, it does not look right. The link criteria is surpose to be a link between two forms where the details match. Yours looks like it is linking itself with itself??
it shoud look more like

stLinkCriteria = "[Form2lastname]=" & Me![form1lastname]

rather than:
strCriteria = "[QME/AME Information]![lastname]=[Forms]![QME/AME Information]![lastname]"


Here is the close button (restore form1) on form2:

Private Sub Command49_Click()
DoCmd.SetWarnings False
DoCmd.Close acForm, "Notification Form", acSaveYes
DoCmd.SelectObject acForm, "QME/AME Information"
DoCmd.Maximize
End Sub

The other thing get rid of gaps in you form,query,tabe,and macro names
eg:[Notification Form] change to [NotificationForm]
other thing get rid of the / in your form names it will confuse VB in the future as / means divide.

hope this helps.

Zero :)
 
I am afraid that when I started building this app I knew little of the conventions. I have so many references to the "/" and gaps that trying to remove them just creates problems. I used find and replace and when I made the changes there were errors everywhere. Too many to make changing practicle for me.

I am trying the code above. I am confused about the line:
stLinkCriteria = "[Form2lastname]=" & Me![form1lastname]
what does "[Form2lastname]" refer to?
Shouldn't it be "[QME/AME Information]![lastname]" ?
 
I am afraid that I know doubt have some problems due to the many naming problems I created. I don't think I can get this problem fixed. I can not get form 1 to return to the original record from which I left to move to form2.

It is unfortunate, as this is my last major bug to fix.

I suppose that I am lucky given the many naming errors I have made that I nly have this problem. It will bother my users that the form changes records from the record they were working on.
 
number2 if you have no probs send me a copy of your program and I will look at solving your problems.

Send email to: rde1@bigpond.net.au
and give me say 1-2days have to fix a problem with my own DB which seems to be taking up a little more time than expected.

zero
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top