Solved

Showing Controls within a function

Posted on 2013-01-20
9
318 Views
Last Modified: 2013-01-20
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.
0
Comment
Question by:Patrick O'Dea
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 77

Assisted Solution

by:peter57r
peter57r earned 200 total points
ID: 38798530
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
 

Author Comment

by:Patrick O'Dea
ID: 38798541
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
 
LVL 77

Expert Comment

by:peter57r
ID: 38798542
Please post the exact statement you are using to display the value.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 300 total points
ID: 38798616
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
 

Author Comment

by:Patrick O'Dea
ID: 38798643
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
 
LVL 77

Expert Comment

by:peter57r
ID: 38798695
"Now folks I am about to change the whole nature of the question!"

Please post a new question.
0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 38798732
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
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 38798734
You could also make a procedure in a standard module with a frm argument, so you could call it for different forms.
0
 
LVL 85
ID: 38798745
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

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question