【发布时间】:2015-12-07 20:14:14
【问题描述】:
在 Excel VBA 中,我有一个类似于以下内容的用户表单,其中用户输入 ID 号,然后在用户表单上显示详细信息:
Private Sub btnIDNo_Click()
Dim IDNo As Long
If txtIDNo.Text <> "" Then
If IsNumeric(txtIDNo.Text) = True Then
lblError.Caption = ""
IDNo = txtIDNo.Text
Worksheets("Details").Activate
Range("B4").Select
While ActiveCell.Value <> "" And ActiveCell.Value <> IDNo
ActiveCell.Offset(1, 0).Select
Wend
If ActiveCell.Value = IDNo Then
txtName.Value = ActiveCell.Offset(0, 1).Value
txtPhone.Value = ActiveCell.Offset(0, 2).Value
Else
lblError.Caption = "Cannot find ID nummber"
End If
Else
lblError.Caption = "Please enter the ID Number in numeric form"
End If
End If
End Sub
在详细信息用户表单上,我有一个“编辑”按钮。单击“编辑”按钮将打开另一个用户表单,用户可以在其中更改该 ID 号的详细信息,但显然不能更改 ID 号本身。为此,我需要将 ID 号从详细信息用户表单传递到编辑用户表单。有没有办法做到这一点?
显示详细信息用户表单的底部打开编辑用户表单类似于以下内容:
Private Sub CommandButton1_Click()
Dim IDNo As Long
If txtIDNo.Text <> "" Then
If IsNumeric(txtIDNo.Text) = True Then
lblError.Caption = ""
IDNo= txtIDNo.Text
ufmEditDetails.Show
ufmShowDetails.Hide
Else
lblError.Caption = "Please enter the ID Number in numeric form"
End If
Range("B4").Select
End If
End Sub
我已经查看了以下链接,但它们似乎没有帮助:
http://gregmaxey.mvps.org/word_tip_pages/userform_pass_data.html
【问题讨论】:
-
您是否考虑过将当前的 2 个表单实现为具有多页控件的单个表单?您可以将当前位于第一个表单上的字段放在多页的第 1 页上,将当前位于第二个表单上的字段放在第 2 页上。您可以在默认情况下使第 2 页不可见,并根据需要在单个表单中的代码中进行控制显示第 2 页