Pass data between UserForms

前端 未结 3 673
栀梦
栀梦 2020-12-14 14:06

Within Excel VBA I have a User Form similar to the following where the user enters an ID number and then the details are displayed on the user form:

Private          


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-14 14:36

    There are serveral ways to solve this problem. The one that I use is declare global or public variable in module

    Example:

    Public commonVariable As String
    

    then in userform you can assign or retrieve value from this variable. For example in userform1:

    Private Sub btnIDNo_Click()
        commonVariable = "UserId"
    End Sub
    

    in UserForm2:

    Private Sub CommandButton1_Click()
        me.txtIDNo.Text = commonVariable 
    End Sub
    

提交回复
热议问题