【发布时间】:2018-05-08 03:45:06
【问题描述】:
我有一个多项目的解决方案,我有一个名为master_ChartofAccount 的主表单,在保存数据后在coa_Create 上,我想调用一个名为showCoa 的Sub 来刷新一个网格coa_Create,这是我的代码:
Private Sub cmdAdd_Click(sender As Object, e As EventArgs) Handles cmdAdd.Click
Dim frm As New coa_Create
frm.ShowDialog(Me)
End Sub
这是cmdSavecoa_Create 上的代码:
Private Sub cmdSave_Click(sender As Object, e As EventArgs) Handles cmdSave.Click
If Not allowSave() Then Exit Sub
Dim str As String
txtKode.Tag = IIf(IsNothing(txtKode.Tag), "", txtKode.Tag)
If txtKode.Tag.ToString = "" Then
str = "insert into t_chart_of_account (coa_code, coa_name, p_code, is_parent, db_cr, bs_is) " _
& "values ('" & objComp.clearSingleQuote(txtKode.Text) & "', '" & objComp.clearSingleQuote(txtNama.Text) & "', " _
& "'" & objComp.clearSingleQuote(txtParentCode.Text) & "', " & IIf(chkParent.Checked = True, 1, 0) & ", " _
& "'" & IIf(optDb.Checked = True, "DR", "CR") & "', '" & IIf(optBS.Checked = True, "BS", "IS") & "')"
Else
str = "update t_chart_of_account set coa_code = '" & txtKode.Text & "', " _
& "coa_name = '" & objComp.clearSingleQuote(txtNama.Text) & "', p_code = '" & txtParentCode.Text & "', " _
& "is_parent = " & IIf(chkParent.Checked = True, 1, 0) & ", db_cr = '" & IIf(optDb.Checked = True, "DR", "CR") & "', " _
& "bs_is = '" & IIf(optBS.Checked = True, "BS", "IS") & "' WHERE id = " & txtKode.Tag.ToString
End If
objComp.setExecute(str, False)
master_ChartofAccount.showCoa() 'error on this line : Reference to a non-shared member requires an object reference
objComp.msgShow(Me, "Data berhasil di simpan.", "Simpan Berhasil", MessageBoxButtons.OK, MessageBoxIcon.Information)
cmdClose_Click(sender, e)
End Sub
为什么会有错误消息:
对非共享成员的引用需要对象引用
在master_ChartofAccount.showCoa()
如何解决这个问题?
还有其他方法可以从另一个Form 调用Sub 吗?
我试过了:
Dim frm as new master_ChartofAccount
frm.showCoa()
但master_ChartofAccount 上的网格不会刷新。
谢谢
【问题讨论】:
-
将您的 master_chartofAccount 表单传递给您的 coa_Create 表单
-
@F0r3v3r-A-N00b 事实上,
frm.ShowDialog(Me)已经完成了这项工作。您可以通过coa_CreateMe.Owner访问它 -
那你应该把coa_Create的父类转换成master_chartofAccount的类类型
标签: vb.net