Form A not updating values in Form B - vba

I have 2 forms. Lets call the FormA and FormB. When a button is pressed in FormA I open formB from FormA. Then I call a function inside FormB that is supposed to update the text fields. When I do this none of the textboxes are filled with values, even though values are being assigned to them ( i can see this in debug mode).
But when I put the same code in the form_load event handler it works fine. Any ideas?
This is FormAs code:
Private Sub btnNew_Click()
[Form_Client Info].Modal = False
Call DoCmd.OpenForm("Client Info")
Call [Form_Client Info].SetValues(lstClients.Column(0, intIndex))
End Sub
and this is FormBs:
Public Sub SetValues(ByVal intID As Long)
Dim arrFields(0 To 8) As Variant
Dim arrValues(0 To 8) As Variant
For i = 1 To 9
arrFields(i - 1) = General.GetField(i, "Clients")
Next i
Call General.GetRecord2(arrFields, arrValues, "Clients")
txtPOBOX.Value = 3434 'arrValues(0)
txtFirstName.Value = arrValues(1)
txtLastName.Value = arrValues(2)
txtPhoneNumber.Value = arrValues(3)
txtStartDate.Value = arrValues(4)
txtEndDate.Value = arrValues(5)
cmbPlan.Value = arrValues(6)
cmbDuration.Value = arrValues(7)
txtPhoneBalance.Value = arrValues(8)
End Sub

As you have this line:
[Form_Client Info].Modal = False
it sounds like your form is saved as modal.
Try to specify the non-modal status when opening it:
Call DoCmd.OpenForm("Client Info", , , , , acWindowNormal)

Related

VBA Run macro with arguments from Command Button click in UserForm

I have a UserForm DataInput in the same VBA project as the module RunOB. These are in the Excel Project Benchmarking.xlsx. I have a command button on the DataInput form in which I would like the module RunOB to run when pressed. Additionally I am passing String arguments from the form to the module.
'Header of 'Run OB' Module
Sub OrganizeBenchmarks(bidNum As String, name As String, _
state As String, year As String, category As String)
The button click method is:
Private Sub CommandButton1_Click()
'...'
End Sub
If possible, it would also be helpful if I could set up a keyboard shortcut to open the DataInput UserForm while I was in the Excel project.
Seems pretty straightforward?
Private Sub CommandButton1_Click()
OrganizeBenchmarks "your", "arguments", "would", "go", "here"
End Sub
Something for you to help developing your own code .........
'Public enum type to add a set of particular vbKeys to the standard key set
Public Enum typePressKeys
vbNoKey = 0
vbExitTrigger = -1
vbAnswerKey = 100
vbLaunchKey = 102
vbPrevious = 104
vbNext = 106
vbSpecialAccessKey = 108
End Enum
Public Sub OrganizeBenchmarks()
Dim stopLoop As Boolean, listOfYears As Variant, bidNum As String, name As String, state As String, year As String, category As String
'For example
listOfYears = Array(2017, 2018, 2019, 2020, 2021, 2022)
stopLoop = False
Load DataInputForm 'Assuming this is the name of your UserForm
With DataInputForm 'Assuming that this name would be an input control in your UserForm
.yearCB.List = listOfYears 'comboboxList control
.yearCB.ListIndex = 2
.Tag = vbNoKey
End With
DataInputForm.Show
Do
If DataInputForm.Tag = vbOK Then
'I have assumed you would use these names for input controls on your UserForm
bidNum = DataInputForm.bidNum_TextBox.Value
name = DataInputForm.name_TextBox.Value
state = DataInputForm.state_TextBox.Value
year = CStr(DataInputForm.yearCB.Value)
category = DataInputForm.category_TextBox.Value
Unload DataInputForm
stopLoop = True
ElseIf DataInputForm.Tag = vbCancel Then
Unload DataInputForm
Exit Sub
Else
stopLoop = False
End If
Loop Until stopLoop = True
'Place additional code here to take whatever actions
End Sub

Force datagridview call row validating after finish input

I'm creating a Form with a Bound Datagridview inside it. On Form_Load or Row_Validating, I added new row to Datagridview by:
Private Sub PurchaseInRowAdd()
'add new row to datagridview
Dim dtRow As DataRow = CType(Me.dgvPurchaseIn.DataSource, DataTable).NewRow()
dtRow.Item("InvoiceID") = 0
dtRow.Item("KindID") = CType(CType(Me.dgvPurchaseIn.Columns("colPurchaseKind"), DataGridViewComboBoxColumn).DataSource, DataTable).Rows(0)("KindID")
dtRow.Item("InvoiceSign") = ""
dtRow.Item("InvoiceNo") = ""
dtRow.Item("InvoiceDate") = New Date(objController.ProcessYear, objController.ProcessMonth, 1)
dtRow.Item("ID") = CType(CType(Me.dgvPurchaseIn.Columns("colPurchaseCustomer"), DataGridViewComboBoxColumn).DataSource, DataTable).Rows(0)("ID")
dtRow.Item("Product") = ""
dtRow.Item("Price") = "0.00"
dtRow.Item("Note") = ""
dtRow.Item("Tax") = CType(CType(Me.dgvPurchaseIn.Columns("colPurchaseKind"), DataGridViewComboBoxColumn).DataSource, DataTable).Rows(0)("Tax")
dtRow.Item("TaxCode") = CType(CType(Me.dgvPurchaseIn.Columns("colPurchaseCustomer"), DataGridViewComboBoxColumn).DataSource, DataTable).Rows(0)("TaxCode")
dtRow.Item("VAT") = ""
CType(Me.dgvPurchaseIn.DataSource, DataTable).Rows.Add(dtRow)
End Sub
The problem here is, when user finished input in that new row and press enter, Row_Validating hasn't been fired because there's no row below it. So how can I force Row_Validating trigger when user finished input and press enter?
I have found this solution, but it doesn't suit my case because I don't want to set Enable Adding to True. I want to handle row adding by code instead.
I found the solution, I subclassed DataGridView and override ProcessDialogKey like this:
protected override bool ProcessDialogKey(Keys keyData)
{
if(keyData == Keys.Enter)
{
KeyEnterPress(this, new EventArgs());
}
return base.ProcessDialogKey(keyData);
}
(I wrote this subclass in C#)
Then handle key enter press in my form like this
Private Sub PurchaseInCellKeyDown(ByVal sender As Object, ByVal e As EventArgs)
If Me.dgvPurchaseIn.CurrentRow.Index = Me.dgvPurchaseIn.Rows.Count - 1 Then
If PurchaseInRowValidate(Me.dgvPurchaseIn.CurrentRow.Index, True) Then
Me.PurchaseInRowAdd()
Me.deselectPurchaseCell(Me.dgvPurchaseIn.CurrentRow.Index)
Me.dgvPurchaseIn.Rows(Me.dgvPurchaseIn.Rows.Count - 1).Cells("colPurchaseSign").Selected = True
End If
End If
End Sub
This line:
Me.dgvPurchaseIn.Rows(Me.dgvPurchaseIn.Rows.Count - 1).Cells("colPurchaseSign").Selected = True
will trigger row validating

How to customize a "MsgBox" control in Visual Basic

Is there a way to customize the MsgBox control in Visual Basic?
I use it quite often to alert users. However it never pops up on the screen; it just appears along the bottom task bar. It also always has a heading similar to "App_data_xxx". Can I improve this in any way?
My searches aren't throwing up much help.
For example:
' Queries user number and password against the database and returns user
Dim matchingusers = From u In db.Users
Where username = u.Email And password = u.Password
Select u
' Checks if a valid user was returned
If matchingusers.Count = 0 Then
MsgBox("Invalid user entered, try again")
Else
SelectedDeveloper = 0
' Set the logged in user for use in the project
GlobalVariables.LoggedInUser = matchingusers.First
You can use the MessageBox function and its many variables. Here's an example of what it can do:
MessageBox.Show("The Displayed text in the messagebox", _
"the text displayed in the title bar", MessageBoxButtons.YesNoCancel, _
MessageBoxIcon.Error, MessageBoxDefaultButton.Button2)
Or you can still use MsgBox and use its variables, though it gives you fewer options. Here's an example:
MsgBox("message text", MsgBoxStyle.Information, "title bar text")
You are using a reference to the MessageBox class without specifying the Method you want to call. You cannot create an instance of MessageBox and therefore cannot pass a string as parameter to try and create one.
Use MessageBox.Show(string messageText) to display the MessageBox with the desired message.
As for your question, you should create your own MessageBox class. With this solution, you get all the options you want and can customize it completely. The call will be a little different :
//C#
var myCustomMessageBox = new CustomMessageBox();
myCustomMessageBox.ShowDialog();
//Vb
Dim myCustomMessageBox As New CustomMessageBox()
myCustomMessageBox.ShowDialog()
The ShowDialog() will be used to create the effect of a messagebox.
In Visual Basic 2008 I had a requirement for a message box that would only stay on for short times and that the time it was on to be variable. I also had the problem that when using extended screen that the msgbox showed up on the extended screen (which was a different form) instead of on the main computer screen. To overcome these problems I created a custom Message Box using a panel on the form I had on the main screen.
To call the message panel DoMessage("The message", Seconds, Buttons to show 1 = Ok only 2 = Yes(ok) and No, 3 = Yes, No and Cancel. If seconds is 0 or not specified then the time to show the panel is set to a long time (10000 seconds) If Buttons to show is not specified it is set to Ok button only. If seconds and buttons are both specified, If no button is clicked the panel will just hide after the timeout.
The responses are 1 if Ok or Yes is clicked, 2 if No is clicked, 3 if Cancel is clicked
It is put into DoMsgResp so you see what is in it to handle the response.
Create the message panel when opening the form by calling MakeMsgPanel()
Dim MessagePanel As New Panel 'The panel
Dim MessageLabel As New Label 'The message
Dim MsgYes As New Button 'Yes or OK button
Dim MsgNo As New Button 'no button
Dim MsgCcl As New Button 'Cancel button
Dim Sleepsecs As Integer 'How long panel shows for
Dim DoMsgResp As Integer 'response 1, 2 or 3 depending which button clicked
Private Sub MakeMsgPanel()
Me.Controls.Add(MessagePanel)
Me.MessagePanel.Controls.Add(MessageLabel)
Me.MessagePanel.Controls.Add(MsgYes)
Me.MessagePanel.Controls.Add(MsgNo)
Me.MessagePanel.Controls.Add(MsgCcl)
MessagePanel.Location = New System.Drawing.Point(Me.Width / 2 - 200, Me.Height / 2 - 100)
MessagePanel.BackColor = Color.PaleGreen
MessageLabel.BackColor = Color.PeachPuff
MessagePanel.BorderStyle = BorderStyle.FixedSingle
MessageLabel.Font = New Font("Arial", 12, FontStyle.Regular, GraphicsUnit.Point)
MessageLabel.AutoSize = True
MessagePanel.AutoSize = True
MessagePanel.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowOnly
MessagePanel.Hide()
MsgYes.Location = New System.Drawing.Point(205, 5)
MsgNo.Location = New System.Drawing.Point(115, 5)
MsgCcl.Location = New System.Drawing.Point(25, 5)
MsgYes.Text = "Yes"
MsgNo.Text = "No"
MsgCcl.Text = "Cancel"
AddHandler MsgYes.Click, AddressOf MsgYes_Click
AddHandler MsgNo.Click, AddressOf MsgNo_Click
AddHandler MsgCcl.Click, AddressOf MsgCcl_Click
End Sub
Private Sub MsgYes_Click()
DoMsgResp = 1
Sleepsecs = 0
End Sub
Private Sub MsgNo_Click()
DoMsgResp = 2
Sleepsecs = 0
End Sub
Private Sub MsgCcl_Click()
DoMsgResp = 3
Sleepsecs = 0
End Sub
Private Sub DoMessage(ByVal Msg As String, Optional ByVal Secs As Integer = 0, _
Optional ByVal Btns As Integer = 0)
'Information messages that can be timed
Dim TheHeight As Integer
Dim TheWidth As Integer
Dim Labelx As Integer
Dim Labely As Integer
DoMsgResp = 0
MessageLabel.Text = Msg
If MessageLabel.Height < 90 Then
TheHeight = 100
Labely = (100 - MessageLabel.Height) / 2
Else
TheHeight = MessageLabel.Height + 10
Labely = 5
End If
If MessageLabel.Width < 140 Then
TheWidth = 150
Labelx = (150 - MessageLabel.Width) / 2
Else
TheWidth = MessageLabel.Width + 10
Labelx = 5
End If
MessagePanel.Size = New System.Drawing.Size(TheWidth, TheHeight)
MessageLabel.Location = New System.Drawing.Point(Labelx, Labely)
MessageLabel.Show()
MessagePanel.Show()
MessagePanel.BringToFront()
MsgYes.BringToFront()
MsgNo.BringToFront()
MsgCcl.BringToFront()
MessagePanel.Focus()
If Btns = 0 Or Btns > 3 Then Btns = 1 'Make ok button if none specified or number too high
If Btns = 1 Then
MsgYes.Text = "Ok"
MsgNo.Hide()
MsgCcl.Hide()
Else 'is 2 or 3
MsgYes.Text = "Yes"
MsgNo.Show()
If Btns = 2 Then MsgCcl.Hide() Else MsgCcl.Show()
End If
If Secs = 0 Then Secs = 10000 'make a long time
If Secs > 0 Then
Sleepsecs = Secs * 2
Do Until Sleepsecs < 1
Threading.Thread.Sleep(500)
Application.DoEvents()
Application.RaiseIdle(New System.EventArgs)
Sleepsecs = Sleepsecs - 1
Loop
End If
MessagePanel.Hide()
End Sub
Private Sub ButtonTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTest.Click
DoMessage("This is To see what happens with my message" & vbCrLf & _
"see if it works good", 0, 3)
If DoMsgResp = 1 Then
MsgBox("Ok was hit")
End If
If DoMsgResp = 2 Then
MsgBox("No was hit")
End If
If DoMsgResp = 3 Then
MsgBox("Cancel was hit")
End If
End Sub

DataGridView not Refreshing/Updating/Reloading Data. After Child form closes

This is a VB.NET, Winforms App. I have a datagridview on "Form1" that uses a databinding.datasource which is an Entity Framework table. I fill the datagridview with the below function on Form1:
Sub PM_UnitViewGrid()
Try
_form1.UnitsBindingSource.DataSource = db.units.Where(Function(f) f.propertyId = _form1.CurrentPropertyId).OrderBy(Function(F) F.unitNumber)
_form1.UnitDataGridView.DataSource = _form1.UnitsBindingSource.DataSource
Dim iCount As Integer = _form1.UnitDataGridView.RowCount
For x As Integer = 0 To iCount - 1
If Not IsNothing(_form1.UnitDataGridView.Rows(x).Cells(4).Value) Then
Dim tid As Integer = _form1.UnitDataGridView.Rows(x).Cells(4).Value
Dim _ten As tenant = db.tenants.Single(Function(f) f.Occupantid = tid)
_form1.UnitDataGridView.Rows(x).Cells(1).Value = _ten.first_name + ", " + _ten.last_name
Else
Dim btnColumn As DataGridViewButtonCell = CType(_form1.UnitDataGridView.Rows(x).Cells(1), DataGridViewButtonCell)
btnColumn.Style.BackColor = Color.Green
_form1.UnitDataGridView.Rows(x).Cells(1).Value = "VACANT"
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return
End Sub
This works great and also assigns the needed values to an unbound column. The problem is that the cells(1) is a button. Which when clicked takes the user to another form as a new dialog window. The function for which is below. However, once the changes are made in that form I need for the datagridview to refresh the data that its using from the database and show the correct data. As it stands right now the values are not updating on the datagridview unless the app is completely exited and restarted. Nothing I have found seems to work and Refresh and Update only redraw the control. I need the underlying datasource to refresh and then the datagridview once the child form is exited.. This has had me stumped for a good 36 hours now and I am lost as to why nothing I am trying is working. ANY and all help would be greatly appreciated.
The sub that loads the child form based on the cells(1) button clicked is as follows:
Private Sub UnitDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles UnitDataGridView.CellContentClick
UnitDataGridView.CommitEdit(DataGridViewDataErrorContexts.CurrentCellChange)
Dim y As DataGridViewCellEventArgs = e
Dim Tid As Integer = Nothing
If e.ColumnIndex = 1 Then
If Not e.RowIndex = -1 Then
If Not IsNothing(UnitDataGridView.Rows(e.RowIndex).Cells(4).Value) Then
currentTenent = UnitDataGridView.Rows(e.RowIndex).Cells(4).Value
TenentIdentification = currentTenent
If Not IsNothing(e) Then
If Not IsNothing(UnitDataGridView.Rows(e.RowIndex).Cells(4).Value) Then
Tid = UnitDataGridView.Rows(e.RowIndex).Cells(4).Value
Dim _ten As tenant = db.tenants.Single(Function(f) f.Occupantid = Tid) 'tenant is a table entity
TenantViewSubs.tenId = _ten.Occupantid
Dim t As New TenantView
t.tenId = tid
t.ShowDialog()
End If
End If
PropertyManagSubs.PM_UnitViewGrid() 'This is the function that is above that fills the datagridview
Else
Dim uTview As New UnassignedTenants
uTview.selectedProperty = selectedProperty 'selectedProperty is Integer
uTview.ShowDialog()
PropertyManagSubs.PM_UnitViewGrid() 'This is the function that is above that fills the datagridview
End If
End If
End If
End Sub
I tried each of the following code blocks after the t.ShowDialog() line with no change at all.
UnitDataGridView.Refresh()
.
UnitsBindingSource.Dispose()
UnitsBindingSource.DataSource = db.units.Where(Function(f) f.propertyId = selectedProperty).OrderBy(Function(f) f.unitNumber)
UnitDataGridView.DataSource = UnitsBindingSource.DataSource
.
UnitsBindingSource.DataSource = nothing
unitsBindingSource.DataSource = db.units.Where(Function(f) f.propertyId = selectedProperty).OrderBy(Function(f) f.unitNumber)
UnitDataGridView.DataSource = UnitsBindingSource.DataSource
I finally fixed this on my own.. It was in the way I passed my db context to the databinding..
I simply wrote the below sub:
Private Sub UpdateValues()
Dim context As New storageEntities 'storageEntities is an Entity
Dim query = context.units.Where(Function(F) F.propertyId = selectedProperty).OrderBy(Function(f) f.unitNumber)
UnitDataGridView.DataSource = query
End Sub
Then anytime a child form updated data I simply call
UpdateValues()
After the dialog box closes.
This may help someone else with the same problems so that is why I am posting it.

Public subs don't work in this scenario

I have a form named FrmDrvouchers. It contains some public subprocedures.
I call these subs from another form which opens from a form which is opened from FrmDrVouchers as a dialog.
When I open FrmDrvouchers directly, everything works. But when I call FrmDrvouchers from another project which is also part of this solution, its public subs don't work when I call them from another (dialog) form.
Here is the code of the Button Click from which I open FrmDrvouchers:
Dim FrmDrv As FrmDrVouchers = New FrmDrVouchers()
FrmDrv.Show()
This works, but those public subs don't. Why?
Thanks For ur response,
It just skip what i want to do, but not throws any Exceptions,
Now I m posting my Code,,, plz have a look on that,,
Here is my Main form's MenuStrip Button Click code :
Private Sub CashPaymentToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CashPaymentToolStripMenuItem.Click
Dim DrVouchers As Transactions.FrmDebitVouchers = Transactions.New FrmDebitVouchers()
DrVouchers.Show()
End Sub
Here is the FrmDebitVouchers's Public Subs which are not working,,, in the sense that they skip the function which i have written but not throwing any Exception,,
Public Sub DrVoucherOPen(ByVal VoucherNo As Integer)
'Filling the Dataset with selected Voucher No to OPen the record
DebitVouchersTableAdapter.FillByVoucher(Flr12131DataSet.DebitVouchers, VoucherNo)
VoucherDateDateTimePicker.Enabled = False
End Sub
Public Sub DrVoucherBodyOPen(ByVal VoucherNo As Integer)
'---------Procedure to Open DrVouchersBody And to OPen it in Datagridview-------------'
'Getting the User No, and if it is admin then load fill dataset and allow user to edit the record
If GetUserNumber() = 1 Then
'Filling the dataset
DebitVouchersBodyTableAdapter.FillByVoucher(Flr12131DataSet.DebitVouchersBody, VoucherNo)
DrBodyDGV.DataSource = Nothing
Dim Sum As New Decimal
'Initializing the SerialNumbers variable
SerialNumbers = New List(Of Integer)
'Setting datagridview to opend record
For i = 0 To Flr12131DataSet.DebitVouchersBody.Rows.Count - 1
DrBodyDGV.Rows.Add()
DrBodyDGV.Rows(i).Cells(0).Value = Flr12131DataSet.DebitVouchersBody.Rows(i).Item("SerialNo")
DrBodyDGV.Rows(i).Cells(3).Value = Flr12131DataSet.DebitVouchersBody.Rows(i).Item("AccountNo")
DrBodyDGV.Rows(i).Cells(6).Value = Flr12131DataSet.DebitVouchersBody.Rows(i).Item("Debit")
DrBodyDGV.Rows(i).Cells(7).Value = Flr12131DataSet.DebitVouchersBody.Rows(i).Item("Narration")
'Getting serial No into List
SerialNumbers.Add(Flr12131DataSet.DebitVouchersBody.Rows(i).Item("SerialNo"))
'Getting Account Name into Datagridview
If Not Not IsNumeric(DrBodyDGV.Rows(i).Cells(3).Value) Then
Dim Qa As New Flr12131DataSetTableAdapters.QueriesTableAdapter
Dim StrAccountName = Qa.GetAccountName(DrBodyDGV.Rows(i).Cells(3).Value)
DrBodyDGV.Rows(i).Cells(5).Value = StrAccountName
Else
End If
Sum += DrBodyDGV.Rows(i).Cells(6).Value
Next
TxtTotal.Text = Sum
'Setting the controls properties for admin
DrBodyDGV.AllowUserToAddRows = True
DrBodyDGV.AllowUserToDeleteRows = True
DrBodyDGV.ReadOnly = False
BtnSave.Enabled = True
BtnDelete.Enabled = True
BtnPrint.Enabled = True
ToUpdate = True
Else
'If user is not admin then load all record and not allow user to modify it or delete
' Bounding the datagridview
Dim Sum As Decimal = 0
BtnSave.Enabled = False
DebitVouchersBodyTableAdapter.FillByVoucher(Flr12131DataSet.DebitVouchersBody, VoucherNo)
DrBodyDGV.DataSource = Flr12131DataSet.DebitVouchersBody
For i = 0 To DrBodyDGV.Rows.Count - 1
If Not Not IsNumeric(DrBodyDGV.Rows(i).Cells(3).Value) Then
Dim Qa As New Flr12131DataSetTableAdapters.QueriesTableAdapter
Dim StrAccountName = Qa.GetAccountName(DrBodyDGV.Rows(i).Cells(3).Value)
DrBodyDGV.Rows(i).Cells(5).Value = StrAccountName
Else
End If
Sum += DrBodyDGV.Rows(i).Cells(6).Value
Next
TxtTotal.Text = Sum
DrBodyDGV.AllowUserToAddRows = False
DrBodyDGV.AllowUserToDeleteRows = False
' DrBodyDGV.edit()
DrBodyDGV.ReadOnly = True
BtnSave.Enabled = False
BtnDelete.Enabled = False
BtnPrint.Enabled = True
End If
End Sub
Here is another the DrVouchersRecord form from which I call Public Subs:
Private Sub DrVouchersRecordDataGridView_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DrVouchersRecordDataGridView.CellDoubleClick
Dim FrmDrVouchers As FrmDebitVouchers = New FrmDebitVouchers()
If FrmDrVouchers.DrBodyDGV.Rows.Count > 1 Then
Dim Ans As Integer
Ans = MsgBox("Unsaved changes will be lost, want to proceed", vbYesNo + vbInformation, "Alert")
If Ans = vbYes Then
Dim VoucherNo As New Integer
VoucherNo = DrVouchersRecordDataGridView.CurrentRow.Cells(0).Value
FrmDrVouchers.DrVoucherOPen(VoucherNo)
FrmDrVouchers.DrVoucherBodyOPen(VoucherNo)
Me.Close()
End If
Else
Dim VoucherNo As New Integer
VoucherNo = DrVouchersRecordDataGridView.CurrentRow.Cells(0).Value
FrmDrVouchers.DrVoucherOPen(VoucherNo)
FrmDrVouchers.DrVoucherBodyOPen(VoucherNo)
Me.Close()
End If
End Sub
My forms sequence is:
FrmMain is my main startUp form
After that FrmDebitVouchers Open on menustripButtonclick
After that DebitVouchersRecord is Open as Dialog from DrmDebitVouchers,,, and from these Public Subs are called
I Have added Refrence also
Waiting for ur answers,
This problem has hit many programmers coming from VB6 to VB.NET.
In your DataGridView_DoubleCellClick event you create a NEW instance of FrmDebitVouchers.
Then your code refers to property/methods/objects of this new INSTANCE, not of the original one created via CashPaymentToolStripMenuItem_Click. (Also note that this new instance is never showed on the screen, so you are sending/requesting changes to an hidden form instance)
Of course, the DrBodyDGV.Rows.Count is zero on this INSTANCE (referenced as FrmDrVouchers) because probably this INSTANCE has never been intialized like the first one.
Try to add a FrmDrVouchers.Show() after the creation and you will see the hidden SECOND INSTANCE of the form class FrmDebitVouchers.
To solve your problem, you need to pass the reference of the first FrmDebitVouchers instance to the DrVouchersRecord form (for example in the constructor or via a public property) and then use that reference instead of creating FrmDrVouchers