none
Changing a forms label value/caption RRS feed

  • Question

  • In my program a user works with any combination of 6 selected work tasks. A user includes an administrator who registers and modifies users (only 2 work tasks). When the user logs into the application they see only the work tasks they do (selected at registration) as buttons on the menu. Which work tasks are displayed are identified by the user ID, therefore the login form needs to communicate to the menu form which buttons to display. How I did this was I hard coded the value of one of my labels on its form so in changing its value with code, I want to keep that new value. The property control code is not working.

    If there is a better way of doing that, let me know. But first I need the property control code to work:

    Private Sub btnLogin_Click()
    On Error GoTo btnLogin_Click_Err
    
    'Capture users PERSAL no. and password and match them against those existing 
    in the _
    & User table.
    'Create dynamic menu buttons according to user logged in
    
    'Open table
    DoCmd.OpenTable "User", acNormal, acReadOnly
    
    'Declare a recordset Holder variable
    Dim recSet As DAO.recordSet
    
    Dim nrPERSAL As String
    Dim strPassword As String
    Dim frm As Access.Form
    Dim ctl As Access.Control
    'Assign entered values to variables
    
    'Assign the variable the data row
    Set recSet = CurrentDb.OpenRecordset("User", dbOpenDynaset)
    
    
            'Forms!MyFormName!MyControlName
    
            Set frm = Forms!Menu 'or
            Set frm = Forms("Menu")
            If Not frm Is Nothing Then
              Set ctl = frm.Form!lblHoldPERSALNum
              If Not ctl Is Nothing Then
                ctl.Caption = nrPERSAL
                Forms!Menu!lblHoldPERSALNum.Caption = nrPERSAL
    '                MsgBox (Forms!Menu!lblHoldPERSALNum.Caption)
    '                MsgBox (txtUser_ID.Value)
    '                MsgBox (ctl.Caption)
              Else
                MsgBox "huh?"
              End If
            Else
              MsgBox "huh!"
            End If
    
            Set ctl = Nothing
            Set frm = Nothing
    
    '            'Forms!FormName!ControlName
    '            Forms!Menu!lblHoldPERSALNum.Caption = nrPERSAL
    '            MsgBox (Forms!Menu!lblHoldPERSALNum.Caption)
    
            Me.txtPassword = LCase(Me.txtPassword)
            strPassword = Me.txtPassword
            'strPassword = (txtPassword.Value)
    
          
            'Call procedures
            Call Login(nrPERSAL, strPassword)
            'Call menuWelcome(recSet)
           ' determineFinancialYear
     End If
    
    btnLogin_Click_Exit:
    DoCmd.Close , "User"
    Exit Sub
    
    btnLogin_Click_Err:
    MsgBox Error$ '"No current record."
    
       ' Resume btnLogin_Click_Exit
       Form_Login.txtUser_ID.SetFocus
    
    End Sub
    
    
    Private Sub Login(ByVal PERSAL As String, ByVal Password As String)
    On Error GoTo Login_ErrHandler
    
    'User found
    
    'Close Login Form
    DoCmd.Close acForm, Me.Name
    DoCmd.Close acForm, "Menu"
    
    'Open Form
    On Error Resume Next
    DoCmd.OpenForm "Menu", acNormal, , , acFormPropertySettings, acWindowNormal
    
    Leave:
    '    On Error Resume Next
    '    On Error GoTo 0
    DoCmd.OpenForm "Menu"
    Exit Sub
    
    Login_ErrHandler:
    MsgBox Err.Number & " - " & Err.Description, vbCritical
    Resume Leave
    End Sub

    Wednesday, June 7, 2017 1:29 PM

All replies

  • In my program a user works with any combination of 6 selected work tasks. A user includes an administrator who registers and modifies users (only 2 work tasks). When the user logs into the application they see only the work tasks they do (selected at registration) as buttons on the menu. Which work tasks are displayed are identified by the user ID, therefore the login form needs to communicate to the menu form which buttons to display. How I did this was I hard coded the value of one of my labels on its form so in changing its value with code, I want to keep that new value. The property control code is not working.

    If there is a better way of doing that, let me know. But first I need the property control code to work:

    Private Sub btnLogin_Click()
    On Error GoTo btnLogin_Click_Err
    
    'Capture users PERSAL no. and password and match them against those existing 
    in the _
    & User table.
    'Create dynamic menu buttons according to user logged in
    
    'Open table
    DoCmd.OpenTable "User", acNormal, acReadOnly
    
    'Declare a recordset Holder variable
    Dim recSet As DAO.recordSet
    
    Dim nrPERSAL As String
    Dim strPassword As String
    Dim frm As Access.Form
    Dim ctl As Access.Control
    'Assign entered values to variables
    
    'Assign the variable the data row
    Set recSet = CurrentDb.OpenRecordset("User", dbOpenDynaset)
    
    
            'Forms!MyFormName!MyControlName
    
            Set frm = Forms!Menu 'or
            Set frm = Forms("Menu")
            If Not frm Is Nothing Then
              Set ctl = frm.Form!lblHoldPERSALNum
              If Not ctl Is Nothing Then
                ctl.Caption = nrPERSAL
                Forms!Menu!lblHoldPERSALNum.Caption = nrPERSAL
    '                MsgBox (Forms!Menu!lblHoldPERSALNum.Caption)
    '                MsgBox (txtUser_ID.Value)
    '                MsgBox (ctl.Caption)
              Else
                MsgBox "huh?"
              End If
            Else
              MsgBox "huh!"
            End If
    
            Set ctl = Nothing
            Set frm = Nothing
    
    '            'Forms!FormName!ControlName
    '            Forms!Menu!lblHoldPERSALNum.Caption = nrPERSAL
    '            MsgBox (Forms!Menu!lblHoldPERSALNum.Caption)
    
            Me.txtPassword = LCase(Me.txtPassword)
            strPassword = Me.txtPassword
            'strPassword = (txtPassword.Value)
    
          
            'Call procedures
            Call Login(nrPERSAL, strPassword)
            'Call menuWelcome(recSet)
           ' determineFinancialYear
     End If
    
    btnLogin_Click_Exit:
    DoCmd.Close , "User"
    Exit Sub
    
    btnLogin_Click_Err:
    MsgBox Error$ '"No current record."
    
       ' Resume btnLogin_Click_Exit
       Form_Login.txtUser_ID.SetFocus
    
    End Sub
    
    
    Private Sub Login(ByVal PERSAL As String, ByVal Password As String)
    On Error GoTo Login_ErrHandler
    
    'User found
    
    'Close Login Form
    DoCmd.Close acForm, Me.Name
    DoCmd.Close acForm, "Menu"
    
    'Open Form
    On Error Resume Next
    DoCmd.OpenForm "Menu", acNormal, , , acFormPropertySettings, acWindowNormal
    
    Leave:
    '    On Error Resume Next
    '    On Error GoTo 0
    DoCmd.OpenForm "Menu"
    Exit Sub
    
    Login_ErrHandler:
    MsgBox Err.Number & " - " & Err.Description, vbCritical
    Resume Leave
    End Sub

    Wednesday, June 7, 2017 1:31 PM
  • This thread has been posted multiple times, so let's all answer the 1st instance which can be found at: https://social.msdn.microsoft.com/Forums/office/en-US/69e14409-6a2f-4b9b-95af-7a9fe0b9886d/changing-a-forms-label-valuecaption?forum=accessdev

    Daniel Pineault, 2010-2016 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    Wednesday, June 7, 2017 2:03 PM
  • " I need the property control code to work"

    What property control code?  Where is it failing, which line of code?  What error are you getting?

    You state "the login form needs to communicate to the menu form which buttons to display" but your code is trying to change ctl captions, why?

    Why are you opening a table ('DoCmd.OpenTable "User", acNormal, acReadOnly)?  There is never a reason to open a table to the user, ever!


    Daniel Pineault, 2010-2016 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net


    Wednesday, June 7, 2017 2:07 PM