Values is not appearing in Current active Form - vb.net

Using VB.Net (Windows Application)
I have one main form(Data entry form), i creating many form at run time.
Code for creating a multiple form at run time.
Button1 click
If IsNothing(frm) OrElse frm.IsDisposed Then
newfrm = New frmEntry
End If
newfrm.Show()
I have popup windows for selcting the value in the Data entry form.
Code for selcting the value from popup windows
Popup Window code
If e.KeyCode = Keys.Enter Then
frmEntry.txtbox1.Text = gridview1.Rows(crRow).Cells("code").Value.ToString().Trim()
End If
The above popup window code is working for Data Entry Form, but it is not working for new forms (at run time)
When i select the value from popup windows means, it is appearing in frmentry textbox, not in newfrm textbox.
Popup windows selected value should appear in current active form.
What wrong in my code.
Need VB.Net Code Help

If the form you open the popup from is what you need to change values in, have you considered passing a reference to the opening form to the popup when you open it? So that you have direct access to the form that has the controls that will need updated?
This constructor in the popup window:
Private mOpeningForm As frmEntry
Public Sub New(OpeningForm As frmEntry)
InitializeComponent()
mOpeningForm = OpeningForm
End Sub
This modified to use the reference to the form sent to the popup form:
If e.KeyCode = Keys.Enter Then
mOpeningForm.txtbox1.Text = gridview1.Rows(crRow).Cells("code").Value.ToString().Trim()
End If
This in the form when the window is being created at runTime:
If IsNothing(mEntryForm) OrElse mEntryForm.IsDisposed Then
mEntryForm= New frmEntry(me)
End If
mEntryForm.Show()
At the top level of the Data Form Class (The one creating the popups)
private mEntryForm as frmEntry
That will allow you to have a reference to the Instance of frmEntry from anywhere in the data form class. (Note that I changed the name of the popup form instance in for the button click event code too)

Related

Is there a way to update a TextBox when is not visible?

I have a TextBox nested inside a TabControl.
Form->TabControl1->TabPage1->TabControl2->TabpPage2->GroupBox->TextBox
When the TabPage1, TabPage2 is selected, so the TextBox is visible to the user all the TextBoxEvents works OK, but when the user selects another TabPage it doesn't work.
I have a timer that send data periodically to know if an external device is present on a specific virtual COM port.
When the external device answer I put that data in that TextBox and set a global flag(boolean) to let the rest of the program that a device is present.
I'm processing the received data on a Private Sub and changing that TextBox with a Lambda expression like this
Me.Invoke(Sub()
Me.VersionFirmwareTxt.Text = RespX.Substring(5)
End Sub)
You can access the TextBox by name from anywhere whether it is visible or not, via casting (CType), and update its text value using the syntax:
'(from within the same Form, e.g., Form1)
CType(TabControl1.TabPages(1).Controls("VersionFirmwareTxt"), TextBox).Text = RespX.Substring(5)
'(from a different Form)
CType(Form1.TabControl1.TabPages(1).Controls("VersionFirmwareTxt"), TextBox).Text = RespX.Substring(5)
If you dynamically added the TextBox to the controls of the parent (TabPage), you will know exactly where the TextBox is located, since you would have already used, e.g.:
TabControl1.TabPages(1).Controls.Add(VersionFirmwareTxt)
Whereas if you manually added the TextBox to the TabPage, you also know the parent control.

VB.NET - Unable to click data within datagridview

I have a datagridview in a form and it opens within a panel. When it opens you can't click any of the cells in table. You can click the cells when the form opens not in the panel. I'm guessing that it's something to do with the way the form opens within the panel, But i'm not sure.
I'm able to reorder the table and resize rows.
People.WindowState = FormWindowState.Maximized
People.FormBorderStyle = Windows.Forms.FormBorderStyle.None
People.Visible = True
Panel2.Controls.Add(People)
Image of table within panel
If you cannot or will not extract your datagridview from your people form (and throw the peopleform away), add this to the People form:
Public Readonly Property TheGrid As DataGridView
Get
Return Me.DataGridViewNameHere
End Get
End Property
Then add the grid to the panel, not the whole form:
Panel2.Controls.Add(People.TheGrid)

How can I simulate a keyPress event on a combo box when I click a buton on the same form im MS Access

I'm creating a form in MS Access with 10 butons simulatin a numeric keypad (only the values 0..9).
I would like to change the value of a combobox control in a subform each time I click on one of these butons. The combo box control is named "projectID"
I tried this but it is not the same as pressing the same key on a keypad.
Private Sub Buton3_Click()
Call Me.frmServDedicacion_Subformulario.Form.projectID_KeyPress(51) 'Ansii code for 3
end sub
I put this procedure as keypress event in order to verifiy the combobox method is executed, and it does (msgbox is ok) but the combobox doesn't receive the KeyAscii value.
Public Sub projectID_KeyPress(KeyAscii As Integer)
MsgBox Chr(KeyAscii)
End Sub
This looks like a problem referring to a control on a sub form from the main form. I still have trouble getting this right so I use a cheat sheet:
http://access.mvps.org/access/forms/frm0031.htm
I created a main form called main and put 10 buttons named button0 - button9 on the form and I dragged a form called mysubform onto the main form to create a subform. mysubform has a textbox named projectID. Then just set the click event to button0 to:
Private Sub button0_Click()
Me!mysubform.Form!projectID = 0
End Sub
Don't forget similar click events for buttons 1-9
some things that may be helpful:
! is the bang operator see:
Bang Notation and Dot Notation in VBA and MS-Access
by default, when you drag a form to create a subform control on another form, access gives the subform control the same name as the dragged form. so here mysubform refers to the subform control and not the original form used to make the subform.
Then .Form gets the form wrapped by the subform control.
I hope this answers your question

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.

How to make a form always stay on top of another form

How to make a form always stay on top of another form.
Also both form's enabled property must be true
I don't wanna make use of topmost property.
Edit 1 :
Another similar question in C# says you can use Form.Owner Property to do the trick , how to make use of this property ?
Edit 2 : The Owner Property works fine untill I try to open it the second time.
This is the error message I get
I believe you need the frm.ShowDialog() instead of frm.Show()
frm is the other form you need to show over your current form and instead of using Show, this will make it as a dialog form over your current form (however you won't be able to select the parent form or the form behind it unless you close the frm form
EDIT
To enable edit on both forms
Form2 frm = new Form2();
frm.Owner = this;
frm.Show();
Hope this helps you out.