表单加载命令

时间:2017-01-12 16:25:03

标签: vb.net

我在Form Load中激活了一个命令,如下所示

Private Sub frm_15_IssueWarning_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lbl_incidentid.Text = frm_6_UpdateIncident.lbl_incidentid.Text
'checks to see if a containment already exists for the Incident, if it does, hide the save containment button
 Dim SqlString As String = "select [containmentid],[incidentid],[containmentdate],[containment] from [containment] WHERE [incidentid] = @incidentid"
    Using conn As New OleDbConnection(ConnString)
        Using command As New OleDbCommand(SqlString, conn)
            command.Parameters.AddWithValue("@incidentid", lbl_incidentid.Text)
            Using adapter As New OleDbDataAdapter(command)
                conn.Open()
                Dim reader As OleDbDataReader = command.ExecuteReader()
                Try
                    If reader.Read() Then
                        Button1.Visible = False
                    Else
                        Button1.Visible = True
                    End If
                Finally
                    reader.Close()
                End Try
            End Using
        End Using
    End Using

所有这些都很有效,但第一个命令

lbl_incidentid.Text = frm_6_UpdateIncident.lbl_incidentid.Text

如果我删除此行并将其放在表单6中,以便在按表格6上的按钮打开表格15时它包含该行

lbl_incidentid.Text = frm_15_IssueWarning.lbl_incidentid.Text

表单加载上的其余命令不再有效,之前这不是问题,因为您只能从一个位置访问表单15,但现在这种情况正在发生变化,因此可以从各个位置打开表单。我可以在这里写一个命令,以便表格知道打开/按下什么形式,以便在此处进行操作并采取相应措施,或者任何人都可以提出另一种解决方法吗?我道歉,如果这没有多大意义,它有点絮絮叨叨。

1 个答案:

答案 0 :(得分:0)

最后我稍微更改了表单,而不是打开表单并立即关闭上一个表单我插入了一个if语句,以便在关闭之前查看之前的表单是打开的,这样新表单可以相应地执行,请参阅以下示例

'checks to see which form is open to see where to get incident if from
    If frm_6_UpdateIncident.Visible = True Then
        Me.lbl_incidentid.Text = frm_6_UpdateIncident.lbl_incidentid.Text
        frm_6_UpdateIncident.close()
    End If
    If frm_17_IncidentView.Visible = True Then
        Me.lbl_incidentid.Text = frm_17_IncidentView.lbl_incidentid.Text
        frm_17_IncidentView.close()
    End If

实际上这很简单,不知道为什么我在第一时间没想到这个