添加,更新和检索用户表单条目

时间:2016-02-10 15:37:57

标签: excel-vba vba excel

首先看看我的设计,因为我必须添加,更新和检索供应商详细信息,例如公司名称,公司地址,联系电话等。当我点击添加按钮时。我真的需要链接到StudentSubjectForm的另一个表单。我的问题是我需要知道在更新和检索按钮中要写入的代码。请告诉我基本知识。

我的设计包括添加,更新和检索按钮。带有3个文本框和3个标签。

enter image description here

当我点击添加按钮时,这些是我的代码。

Private Sub AddButton_Click()

 Dim companyName As String
 Dim companyAddress As String
 Dim contactNo As String

    companyName = CompanyNameTextBox.Text
    companyAddress = CompanyAddressTextBox.Text
    contactNo = ContactNumberTextBox.Text

    'To transfer student details to StudentSubjectForm window
    StudentSubjectForm.StudentNameDisplayLabel.Caption = studentName
    StudentSubjectForm.AdmissionNoDisplayLabel.Caption = admissionNo
    StudentSubjectForm.CourseDisplayLabel.Caption = courseName
    'To show the student subject form
    StudentSubjectForm.Show

End Sub

1 个答案:

答案 0 :(得分:0)

为什么不创建静态数据结构来组织公司数据?无论您的问题如何,这可能有助于保持清晰。

Type xCompanyData
    Name As String
    Address As String
    Number As String
End Type

然后......对于多家公司,制作CompanyData的实例......

Dim CompanyData() As xCompanyData
' # companies? = n
ReDim CompanyData(1 To n)

'example
CompanyData(1).Name = 'userdata form stuff here
相关问题