Home > Mobile >  How to pass information from a userform textbox to a worksheet activeX textbox (or label) in vba exc
How to pass information from a userform textbox to a worksheet activeX textbox (or label) in vba exc

Time:12-09

(I keep getting a "Runtime error 438" after adding

wsh.Shapes("lblWelcome").TextFrame.Characters.Text = Login.tbxUsername.Value)

Code:


    Dim user As String
    Dim password As String
    Dim wsh As Worksheet
    Set wsh = ThisWorkbook.Sheets("Go to")
    
    user = Me.tbxUsername.Value
    password = Me.tbxPassword.Value
    
    If (user = "nazar.f" And password = "BCG300") Or (user = "barri.d" And password = "CGI2043") Or (user = "moros.j" And password = "TDI2039") Or (user = "reyes.l" And password = "PDQ3021") Or (user = "matt.a" And password = "GER0998") Or (user = "huang.c" And password = "HYG2094") Then
        Unload Me
        Application.Visible = True
        wsh.Activate
        wsh.Shapes("lblWelcome").TextFrame.Characters.Text = Login.tbxUsername.Value

    Else
        MsgBox "Invalid Login Credentials. Please try again.", vbOKOnly   vbCritical, "Invalid Credentials"
    End If

CodePudding user response:

Use the sheet's OleObjects collection.

For example:

Activesheet.Oleobjects("Textbox1").Object.Text = "Hi"
Activesheet.Oleobjects("Label1").Object.Caption = "Hi"
  • Related