By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,475 Members | 1,915 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,475 IT Pros & Developers. It's quick & easy.

Return form value from a custom module

maxamis4
Expert 100+
P: 295
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function AuditCheck(frm As Form)
  3.  
  4. Dim setformvalue As String
  5. Dim ctl As Control
  6.  
  7. For Each ctl In frm
  8.     If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acListBox Then
  9.  
  10.         mytemp = ctl.Name
  11.  
  12. LINE 1 ------->  'setformvalue = Forms![frm_Admin_employee]![txt_empid]
  13.  
  14. LINE 2 ------->  setformvalue = frm.Controls.ctl.Name
  15.  
  16.     End If
  17. Next ctl
  18. Set ctl = Nothing
  19. End Function
  20.  
  21.  
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.
Jun 18 '12 #1

✓ answered by maxamis4

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

Expand|Select|Wrap|Line Numbers
  1. setformvalue = Forms(frm.Name).Controls(setformvalue).Value

Share this Question
Share on Google+
4 Replies


maxamis4
Expert 100+
P: 295
Have figured out the fix here is the line syntax needed:

Expand|Select|Wrap|Line Numbers
  1. setformvalue = Forms(frm.Name).Controls(setformvalue).Value
Jun 18 '12 #2

TheSmileyCoder
Expert Mod 100+
P: 2,321
It would be alot simpler to use:
Expand|Select|Wrap|Line Numbers
  1. setformvalue=ctl.Value
Jun 18 '12 #3

maxamis4
Expert 100+
P: 295
I actually tried that before I posted and it does not work. Any ideas why?
Jun 19 '12 #4

TheSmileyCoder
Expert Mod 100+
P: 2,321
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.
Jun 19 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.