473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Returning to all previous forms

Hello guys,
In my project, I have a form named frmDetails which can be accessed by a number of forms like frmAdmin, frmStaff etc. My problem is I want to return to the previous form (may be frmAdmin or frmStaff) from which I accessed frmDetails.
For this, I want to put a button btnBack on the form frmDetails.
Thank you in advance :)
Jun 5 '17 #1

✓ answered by PhilOfWalton

I presume you have a command button on your frmAdmin, frmStaff etc. to open FrmDetails.

So the code for the command button should be
Expand|Select|Wrap|Line Numbers
  1. Private Sub CmdOpenDetails_Click()
  2.  
  3.     DoCmd.OpenForm "FrmDetails", , , , , , Me.Name
  4.  
  5. End Sub
  6.  
This passes the name of the calling form (FrmAdmin or FrmStaff) to the FrmDetail.

The relevant code in the FrmDetails is

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Dim Args As String
  5.  
  6. Private Sub Form_Open(Cancel As Integer)
  7.  
  8.     Args = Me.OpenArgs
  9.  
  10. End Sub
  11.  
  12. Private Sub Form_Close()
  13.  
  14.     DoCmd.OpenForm Args
  15.  
  16. End Sub
  17.  
So on opening the FrmDetails, it gets passed the information of the calling form, and on closing the FrmDetails it opens the name it was passed.

Phil

5 1055
PhilOfWalton
1,430 Expert 1GB
I presume you have a command button on your frmAdmin, frmStaff etc. to open FrmDetails.

So the code for the command button should be
Expand|Select|Wrap|Line Numbers
  1. Private Sub CmdOpenDetails_Click()
  2.  
  3.     DoCmd.OpenForm "FrmDetails", , , , , , Me.Name
  4.  
  5. End Sub
  6.  
This passes the name of the calling form (FrmAdmin or FrmStaff) to the FrmDetail.

The relevant code in the FrmDetails is

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Dim Args As String
  5.  
  6. Private Sub Form_Open(Cancel As Integer)
  7.  
  8.     Args = Me.OpenArgs
  9.  
  10. End Sub
  11.  
  12. Private Sub Form_Close()
  13.  
  14.     DoCmd.OpenForm Args
  15.  
  16. End Sub
  17.  
So on opening the FrmDetails, it gets passed the information of the calling form, and on closing the FrmDetails it opens the name it was passed.

Phil
Jun 5 '17 #2
Thank you. That was short and to the point.
It works fantastic with the scenario I provided earlier. But, when I want to link frmAdmin and frmStaff (going back to each other), it always tells me "Invalid use of null" and the statement Args = Me.OpenArgs is highlighted. I wrote the following code. Please correct me where I am going the wrong way.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. Dim Args As String
  4.  
  5. Private Sub goToStaff_Click()
  6. DoCmd.OpenForm "FrmStaff", , , , , , Me.Name
  7.  
  8. End Sub
  9.  
  10. Private Sub goTodetai_Click()
  11.  DoCmd.OpenForm "FrmDetails", , , , , , Me.Name
  12. End Sub
  13.  
  14. Private Sub Form_Open(Cancel As Integer)
  15.  
  16.     Args = Me.OpenArgs
  17.  
  18. End Sub
  19.  
  20. Private Sub Form_Close()
  21.  
  22.     DoCmd.OpenForm Args
  23.  
  24. End Sub
Jun 8 '17 #3
PhilOfWalton
1,430 Expert 1GB
Very odd

I must confess that it should say

Expand|Select|Wrap|Line Numbers
  1. Args = Nz(Me.OpenArgs)
  2.  
I am at a loss to know why it isn't working......

I Know

The
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.  
  3.     Args = Nz(Me.OpenArgs)
  4.  
  5. End Sub
  6.  
Should be the open event on both the FrmDetails and FrmStaff. That way, you "Pass" the name of the calling form to te form being opened.

Equally the Close event should be on both the FrmDetails and FrmStaff. Here you open the form whose name has been passed to it when you opened the form.

I have a feeling that all the code is on your main form

Phil
Jun 8 '17 #4
NeoPa
32,556 Expert Mod 16PB
In short, all Forms that you open with this method should have the code in their Form_Open() & Form_Close() event procedures to handle the Args string value and any form that is opening another form (or report indeed) should have the code that passes its name in the OpenArgs parameter.

I would actually do it slightly differently, as I tend simply to hide and unhide the form that opens another one. So, if frmA is the form that's open to start with, and it calls frmB, then the code would be as below :
frmA
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub cmdOpenB_Click()
  5.     Call DoCmd.OpenForm(FormName:="frmB", OpenArgs:=Me.Name)
  6. End Sub
frmB
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private strCaller As String
  5.  
  6. Private Sub Form_Open(Cancel As Integer)
  7.     strCaller = Nz(Me.OpenArgs, "")
  8.     If strCaller > "" Then Forms(strCaller).Visible = False
  9. End Sub
  10.  
  11. Private Sub Form_Close()
  12.     If strCaller > "" Then Forms(strCaller).Visible = True
  13. End Sub
Notice, with the hiding code being in the called form, the calling form doesn't have to know if the called form has been coded to handle hiding or not. As long as each form has either no code or both sets of code (In Form_Open() as well as Form_Close()) then it will work consistently. Equally, when a called form is opened directly from the database window, it won't have any issues trying to make the calling form visible again.

NB. Hiding is preferable in most cases as it doesn't lose any of its settings and won't need to get the data again if it has any. It also won't need to go through the opening sequence. That last bit's usually insignificant but unnecessary is unnecessary ;-) Also consider a form used for filtering that opens a selected item. When you return to that form you generally prefer the same criteria to be set in order to allow you to continue seamlessly.
Jun 8 '17 #5
Thank you so much guys. my problem is solved with the Nz command. thank you for your time and effort
Jun 11 '17 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: Steve Jorgensen | last post by:
Yup, Steve's full of tips, but hey, it makes him feel important, right? Ok, here goes. I've been trying to improve encapsulation by putting code in the same object as the stuff it affects, so I...
4
by: Baz'noid | last post by:
Hi all, As the size of my database and the number of users grows, i've found a horrible bug in the system with a very simple solution (but i don't know how to implement it)... If two people...
5
by: Steve Strik | last post by:
My Problem: I have created a database here at work that is exhibiting some very strange behaviour. Essentially the database is structured in a manner where one table is a master record table...
2
by: Mani P.S via .NET 247 | last post by:
(Type your message here) Hi I'm new to asp.net and I need some help I have three forms with some textboxes.I want to pass the values of the textboxes of form1 and form2 to the third form For this...
7
by: gordon | last post by:
Hi, I have a series of forms that collect information from a user. When I write out my information to a text file after the last file, the values of the previous forms seem to be blank. I would...
7
by: Justin Hoffman | last post by:
I am new to vb.net programming and am just exploring the way databinding works with Windows forms and am having trouble with some fairly basic customization of data entry. The form uses the...
3
by: philelpko | last post by:
Morning all, Hopefully someone can give me a pointer as I am having no luck finding a solution. Each of my records needs an expense ID (i.e. P235-994-EXP-001). I have code set up to extract...
2
by: Mike | last post by:
Hi, I'm having a problem with modal forms on windows. I've written a very short test program, with a main window and a form called from the main window. The form is set to modal with...
14
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using VS2005 and .net 2.0. I'm creating an application that has 3 forms. I want allow users to move forward and backward with the forms and retain the data users have entered. I thought...
13
by: staeri | last post by:
I use javascript:history.go(-1) to return to the previous page. I've now found out that when returning to the previous page all selections that the user made in dropdownlists are lost. How can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.