Showing Controls within a function

Okay folks ... this is probably fairly simple and basic!

1. In my VBA is have a "STOP"
2. When the code stops I print the control "email" in the immediate window.
E.g. ?Window

3. The immediate window then displays "Joeb@gmail.com"

4. I then press F8 which takes me into a FUNCTION (i.e. the next line of VBA)

5. However, when I am in the function I , once again, try to print the "email".  (i.e. I repeat point 2 above).

6. In this case the email does NOT display !!

7. QUESTION: How can I display my email within the called function.
Patrick O'DeaAsked:
Who is Participating?
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Connect With a Mentor Infotrakker SoftwareCommented:
I print the control "email" in the immediate window
I'd assume because "email" is on the FORM, and your Function cannot reference that Form.

If the form is open, you could do this:

?forms("YourformName").email

You could also use that syntax to reference the value in your function, if needed.
0
 
peter57rConnect With a Mentor Commented:
How are you halting the code within the function?


You can use a statement like..

Debug.print something

to print any value into the immediate window.
0
 
Patrick O'DeaAuthor Commented:
I am halting code with a stop command.

Is there any reason that I should not be able to print a control value within a function?

(I could be making a fundamental error here!)
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
peter57rCommented:
Please post the exact statement you are using to display the value.
0
 
Patrick O'DeaAuthor Commented:
Yes, LSM that is the solution.

(altho' I don't really understand why my function cannot "see" the form??  but that's a discussion for a different day).

Now folks I am about to change the whole nature of the question!

See attached - very very simple database.

Note the variant called "AllFields"

I want a new function.
This function will display the actual value in each field in the array "AllFields".
So, for instance, the function will display the name "Tom".

The function will display the "OldValue" and the current value of the field.

Could someone give me guidance as to how I can displays these values.
Actually, what I really need is the few lines of VBA to show these values.
0
 
peter57rCommented:
"Now folks I am about to change the whole nature of the question!"

Please post a new question.
0
 
Helen FeddemaCommented:
Here is some code to display the values of bound controls (textboxes and combo boxes) in the current form record:

Private Sub cmdPrintValues_Click()

   Dim ctl As Access.Control
   
   For Each ctl In Me.Controls
      If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
         Debug.Print "Control name: " & ctl.Name & "; control value: " & ctl.Value
      End If
   Next ctl

End Sub

Open in new window

0
 
Helen FeddemaCommented:
You could also make a procedure in a standard module with a frm argument, so you could call it for different forms.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I don't really understand why my function cannot "see" the form?
The function can "see" the form, but you must tell it where to look:

Forms("YourForm").YourControl
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.