vb.net Move between two form with option - vb.net

at first i am sorry for my weak english but i will try my best to explain my issue
i am new in programming so i got idea but i don't know if can be happen or not
the idea is , i have 2 form separated each form have there cods , but i want to add button in form one its open the second form, to add thing to the second one , but i need to return to first form when i close the second form
can i do something like that ??
for clarification the second form i can open it from other ways and have own function and the first form too
UPDATING !!!
at first thank for all your answers and not useful vote ,second yes i am new but not that much i know how to use formname.show() and formname.close() etc..... ,the issue not about usual ways to open and close forms, for example in form one i input information about user one of the option is where he live, the country choosing from dropbox ,next to the dropbox there button named add new country the button open new form to add new country when i add new country and closed the form back to the first form , and just to be know there button in the third form (setting) to open the form add new country ,IN SHORT WORD I DON'T NEED TO OPEN THE FIRST FORM EVERY TIME I CLOSE THE SECOND ONE , ONLY RETURN TO THE FIRST FORM IF I CAME FROM THE BUTTON THAT I CLICKED IN FORM ONE

put this on action
formname.show() 'for opening a new form
formname.close() 'for opening closing the form
formname.showdialog() 'Where you cant click the main form``

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'show form 2
Form2.Show()
'move text from one form to another
Form2.TextBox1.Text = TextBox1.Text
End Sub

Related

Call a windows form dynamically by its title in vb.net

I'm stuck with something that I have tried to overcome before and couldn't.
Last time I worked around it, but I really need to nail this down.
I have a multi-instance form which lists details of jobs, so a user may have 6 or so instances of this form open, all with different info. Lets call that form A.
Within form A there is an option to assign that job to a user.
Clicking that link label opens a new form using showdialog where a combobox is populated with logged in users... Lets call that form B.
What I want to do is have the value selected on form B passed back to form A, however because form A has multiple instances, I'm not sure how to call it.
Form A is JobDetails.vb, and always has a form title of "Job XXXXX Details", so I was hoping there was a way I could use the title to call it.
Hope that all make sense! Thanks in advance, and apologies if its a dumb question. I feel like this should be something obvious, but I just can't achieve it.
As shown on the help page of ShowDialog, you can easily alter the main form when the dialog-form is closed. So you could do something like this:
Public Sub ShowMyDialogBox()
Dim testDialog As New Form2()
' Show testDialog as a modal dialog and determine if DialogResult = OK.
If testDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
Me.Text = String.Format("Jobs of {0}", testDialog.cmboUsers.SelectedValue)
Else
Me.Text = "Jobs"
End If
testDialog.Dispose()
End Sub

can docmd.gotorecord,,acnew open in new window?

I have a form which is bound to a table, and lets a user scroll through existing records in the table and make changes. I'm now trying to build a button which allows the user to insert a new record. So far I have a button with some basic vba:
Private Sub btnNew_Click()
DoCmd.GoToRecord , , acNewRec
End Sub
This opens a new record in the same form and has no way of assuring a user that the record has been saved. What i would really like is for the this to open a new 'pop up'form with a save button on
how would i do this?
Go to the design view of the Form, add a button name it saveBtn. Under its properties, set the visibility as No. Now in the Form Current method, check if the form has the new record, if so make the button visible.
Private Sub Form_Current()
Me.saveBtn.Visible = Me.NewRecord
End Sub
Using this method, the current form could be used for navigation and editing and when it sits on a new record a Save button will be available where in you could add the code to run a Save command or close the Form, which by default will save the record.

Based on form combobox selection to open the another form and move the value

I am new to access.
I have DFR form, From DFR form we are copy the record to different history card based on the asset code.
So what I did now I create one button and generate the code to open the form based on combobox selction ( the combobox contain the assed code no).
AFfter complete the DFR form press generate button it is opening the form what asset code contain in the combobox but i dont know how to copy the value from DFR form to the opened to asset code form. Because all the time I am not opening the same form so in the VBA I am not able to mention form name. Please help me
The code for the button:
Private Sub Command632_Click()
DoCmd.OpenForm Combo99.Value
End_Sub
according to the above command the form opened but iam not able move the value
For example I am using two form one is called as a DFR onother one is Mech_history card
in this case i know the designation form name. but above case i dont know the form name so please help me
What you want to do is pass an argument to the form that you are opening. This is possible as follows:
Private Sub Command632_Click()
DoCmd.OpenForm Combo99.Value, , , , , , "example"
End_Sub
Then in the form that is opening, you can use it for example as such:
Private Sub Form_Load()
Me.Label0.Caption = OpenArgs
End Sub
Where it will set the caption of Label0 to "example".
The OpenArgs argument is a single value, but you can pass multiple values by concatenating. This is already very well explained here: http://www.fmsinc.com/MicrosoftAccess/Forms/openargs/index.htm so it doesn't seem of added value of me to reword that for my answer here. Please take a look on that website.

How to refresh an access form

I am building an MS Access application in which all the forms are modal. However, after data change in a form, I want to refresh the parent form of this form with newer data. Is there any way to do it. To elaborate further :
Consider there are two forms, Form A and Form B. Both are modal form. From Form A, I initiate Form B, and now Form B has the user attention. But at the close of form B, I want to refresh the Form A. Is there a way to do it?
You can repaint and / or requery:
On the close event of form B:
Forms!FormA.Requery
Is this what you mean?
No, it is like I want to run Form_Load
of Form A,if it is possible
-- Varun Mahajan
The usual way to do this is to put the relevant code in a procedure that can be called by both forms. It is best put the code in a standard module, but you could have it on Form a:
Form B:
Sub RunFormALoad()
Forms!FormA.ToDoOnLoad
End Sub
Form A:
Public Sub Form_Load()
ToDoOnLoad
End Sub
Sub ToDoOnLoad()
txtText = "Hi"
End Sub
"Requery" is indeed what you what you want to run, but you could do that in Form A's "On Got Focus" event. If you have code in your Form_Load, perhaps you can move it to Form_Got_Focus.
I recommend that you use REQUERY the specific combo box whose data you have changed AND that you do it after the Cmd.Close statement. that way, if you were inputing data, that data is also requeried.
DoCmd.Close
Forms![Form_Name]![Combo_Box_Name].Requery
you might also want to point to the recently changed value
Dim id As Integer
id = Me.[Index_Field]
DoCmd.Close
Forms![Form_Name]![Combo_Box_Name].Requery
Forms![Form_Name]![Combo_Box_Name] = id
this example supposes that you opened a form to input data into a secondary table.
let us say you save School_Index and School_Name in a School table and refer to it in a Student table (which contains only the School_Index field). while you are editing a student, you need to associate him with a school that is not in your School table, etc etc
to refresh the form you need to type -
me.refresh
in the button event on click

Problem with datagridview and AddNew

I've created a VB 2008 program to track work requests. It all works perfectly on a VISTA box, but I am having an issue with the program on an XP environment with adding new records.
Basically I've got 2 tabs: TAB 1 holds a datagridview with limited info and a calendar. Selecting dates on the calendar change the info in the datagridview. TAB 2 holds all the available info for that record in text/combo boxes. Both the datagridview and text boxes use the same Binding Source, so they are always in sync whenever the user selects a row from the datagridview. When you select the NEW button, TAB 2 appears with all the text boxes empty so the user can add data. If you look back on TAB 1, you see an empty, new row added to the datagridview (user can not directly add a row in the datagridview as AllowUserToAdd is set to false). If you let the app stay in the AddNew record state on VISTA, you remain on that new record until you select SAVE or CANCEL. On XP, however, after 1 minute time lapse, all the empty fields will eventually fill in with an existing record for that particular calendar day. When you look back on TAB 1, you no longer see the new empty row, you only see existing records previously saved.
Any ideas on how to resolve?? Thanks for any assistance.
Here is the code for adding new records:
Private Sub cmdNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNew.Click
'Focus on Work tab
TabControl1.SelectedTab = tabWork
'Change the files from read-only
bEditMode = True
ChangeEditMode()
'Clear the current information stored in the fields
Try
Me.BindingContext(WorkRequestBindingSource).AddNew()
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
'Hidden text boxes populate with current selected calendar
'Used to populate TimeIn and DateNeed because if never clicked on, will populate as NULL on save
dtpDateNeed.Text = txtDate.Text
dtpTimeIn.Text = txtTime.Text
End Sub
This is definitely an environmental issue. To solve the problem I would need to know which browsers you are using on each machine and some of the settings on each.
It sounds like the XP machine is refreshing the page after a timeout period and therefore munging the new record. I have seen that happen before and it stinks.
You might need to consider saving some more state information in the viewstate to catch that kind of thing.
If the code is exactly the same I wonder if it is an environment issue e.g. something like different international options or version of framework?