Return form value from a custom module

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maxamis4
    Recognized Expert Contributor
    • Jan 2007
    • 295

    Return form value from a custom module

    Hello folks,I am playing with a new function that will loop through every control. In addition to looping through the forms controls I want to obtain the value of that the control has. That is where I am having problems. I can loop through the controls but I can not get the values from the forms:

    Code:
    Public Function AuditCheck(frm As Form)
    
    Dim setformvalue As String
    Dim ctl As Control
    
    For Each ctl In frm
        If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acListBox Then
    
            mytemp = ctl.Name
        
    LINE 1 ------->  'setformvalue = Forms![frm_Admin_employee]![txt_empid]
    
    LINE 2 ------->  setformvalue = frm.Controls.ctl.Name
        
        End If
    Next ctl
    Set ctl = Nothing
    End Function
    As you can see i have to examples of setformvalue. The first example in Line 1 works but I have to specify the form and control manually. What I am trying to do with Line 2 is use the automated method in the form loop to get the control (which works) and then figure out the syntax on how to duplicate Line 1 problematically in Line 2.
  • maxamis4
    Recognized Expert Contributor
    • Jan 2007
    • 295

    #2
    Have figured out the fix here is the line syntax needed:

    Code:
    setformvalue = Forms(frm.Name).Controls(setformvalue).Value

    Comment

    • TheSmileyCoder
      Recognized Expert Moderator Top Contributor
      • Dec 2009
      • 2322

      #3
      It would be alot simpler to use:
      Code:
      setformvalue=ctl.Value

      Comment

      • maxamis4
        Recognized Expert Contributor
        • Jan 2007
        • 295

        #4
        I actually tried that before I posted and it does not work. Any ideas why?

        Comment

        • TheSmileyCoder
          Recognized Expert Moderator Top Contributor
          • Dec 2009
          • 2322

          #5
          It should work, so You will need to be more specific in regards to which way it doesn't work. Is it giving you an error, and if so, what is the error(nr and description)? Is nothing happening?


          Things I could imagine happening is if the control value is null, that the code would complain. That however should be no different from the approach you say is working.

          Or if you used "my" approach before you added the check to see if its a textbox/combobox/listbox.

          Comment

          Working...