?
Solved

How do I pass data input on userform back to calling module?

Posted on 2010-08-18
7
Medium Priority
?
433 Views
Last Modified: 2012-05-10
Hi
I hope someone can help me.  I have created (or more aptly, cobbled together!) a macro in Outlook that, having done various things then calls a user form for the user to enter data.  What I'm now stuck on is how to pass that collected data back into the calling macro to do more stuff with.  I have tried to find a solution to what must be a basic VB activity, but have failed miserably so far.  Could someone please explain in simple terms the process required?

Many thanks.
0
Comment
Question by:LindaWeston
[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
  • 3
7 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 33463861
Hi, LindaWeston.

Create public variables to hold the data the user form needs to pass back to the calling macro.  Before destroying the userform have it set the values into the public variables.  Something like this

Public varA, varB, varC

Sub YourMacro()
   dim frmX as New UserFormX
   frmX.Show
   'Code that does something with varA'
   'Code that does something with varB'
End Sub

'Code in the form'
varA = SomeValue from the form
varB = SomeOtherValue from the form
0
 
LVL 4

Expert Comment

by:javaftper
ID: 33463942
manipulating/utilising data from VBA forms is relatively easy once you know what you're doing with the object model.
there are two main things you will need to do-
1.  Set a trigger event for when you want to collect the data from the form (for example when they click on OK button).
2.  Retrieve the data from the relevant text boxes, combo boxes etc.

Without having more information it is difficult to provide an exact solution but you should be able to take these two key areas from the following example-

 Private Sub CommandButton1_Click()
          Dim name As String
          Dim company As String
          Dim status As String

          response = MsgBox("Do you want to add this name, company and status?", _
              vbYesNo)

          If response = vbYes Then
              name = TextBox1.Text
              company = TextBox2.Text
              status = TextBox3.Text

         'comment- do whatever you want with the data you have collected here

          Else
              Unload Me
          End If

End Sub
0
 

Author Comment

by:LindaWeston
ID: 33464387
Thanks very much for these comments.  I'll see what I can do and then post back later.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:LindaWeston
ID: 33466011
Hi, well I tried BlueDevilFan's information first as it seemed simpler and this worked perfectly for me, so I didn't need to try the info from javaftper.  Therefore what is the fair way to award points here? I don't want to upset anyone as I might need more help soon! ;)
0
 
LVL 76

Expert Comment

by:David Lee
ID: 33466079
Points should go to the posts used to solve the problem.  
0
 

Author Comment

by:LindaWeston
ID: 33466138
Thanks for the guidance.  And thanks very much for the solution. I have learnt a lot from this - particularly from the words 'Before destroying the userform ....'  - I hadn't thought of it like that before and now a lot more makes sense!
0
 
LVL 76

Expert Comment

by:David Lee
ID: 33466319
You're welcome.  Always happy to help.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

650 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