Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
If I was to go from StaffAccountView to Room Booking. How would I be able to do this? I have looked at many different posts but cannot find anything that will work. Do I have to create a Global Variable? I've tried this from posts but it doesn't seem to work. Can anyone help?

Dim ExitedForm as Form


In the exit button

ExitedForm=Me 
StaffAccountView.Show 
me.hide


On the Back Button

ExitedForm.show


I want the button to be able to go back to the previous form which is StaffAccountView

What I have tried:

I have tried the code above but it does not work since making it public still won't share across a form
Posted
Updated 18-May-17 16:45pm
Comments
[no name] 18-May-17 17:04pm    
Your code:
A. doesn't make any sense
B. Doesn't match the description of your problem.
And you say "the button" and "making it public" like we would any idea at all what button you are talking about or what something is being made public has anything at all to do with your code.
selvam palanisamy 23-May-17 6:57am    
exact definition!!!!
Ralf Meier 19-May-17 1:43am    
I'm not sure that Solution 1 matches to your Problem - therefore my question :
Your 'StaffAccountView' is called only from one form ... or is it called from various forms ? So you want to go back to this form ... ?

1 solution

Hi Member 13209355,

I am assuming your first form name is StaffAccountViewForm, and second form name is RoomBookingForm.

you need to pass the StaffAccountViewForm instance as a parameter to the constructor of the RoomBookingForm. In the constructor you save the form instance to a local variable of the RoomBookingForm. So the following line:
VB
Dim ExitedForm as Form 'Should not be a generic form variable.
changes to:
VB
dim ExitedForm As StaffAccountViewForm 'Should be specific to the first form
In the constructor of this form:
Public Sub New(form1 As StaffAccountViewForm)
    InitializeComponent() ' This call is required by the Windows Form Designer.
    ExitedForm = form1
End Sub
The call from the StaffAccountViewForm changes to following:
VB
Dim frm2 As RoomBookingForm = New RoomBookingForm(Me) 'Passing the current instance of me
frm2.Show() 'Show the second form
Hide() 'Hide current form
Back button code is okay. Perhaps you would like to hide or close the second form. Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900