Solved

VB code syntax

Posted on 2013-02-06
4
304 Views
Last Modified: 2013-02-06
Hi,

What is the VB code to populate data in a current form based on data from another form? The current form (formA) was opened by one of two other forms.

if (formB is open)  then
    FieldO_formA = FieldFrom_formB
else
   FieldOn_formA = FieldFrom_formC
 endif

formA was opened by either formB or formC

Thank you,
AEN
0
Comment
Question by:allfredeneuman
[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
  • 2
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 400 total points
ID: 38859000
if  CurrentProject.Allforms("FormB").IsLoaded then
    FieldO_formA = Forms!formB.YourFieldName
else
   FieldOn_formA = Forms!formC.YourOtherFieldName
 end if

Open in new window

0
 
LVL 61

Expert Comment

by:mbizup
ID: 38859011
If your code is on the current form (FormA), you can do this:

if  CurrentProject.Allforms("FormB").IsLoaded then
    Me.YourFieldOnFormA  = Forms!formB.YourFieldName
else
   Me.YourFieldOnFormA = Forms!formC.YourOtherFieldName
 end if

Open in new window



If the code is NOT on form A, use the full form reference:

if  CurrentProject.Allforms("FormB").IsLoaded then
    Forms!FormA.YourFieldOnFormA  = Forms!formB.YourFieldName
else
   Forms!FormA.YourFieldOnFormA = Forms!formC.YourOtherFieldName
 end if

Open in new window

0
 
LVL 13

Assisted Solution

by:Ryan
Ryan earned 100 total points
ID: 38859416
Credit to mbizup, but here's a shorter, less efficient, harder to read 1 line version.  Just so you're aware there's other ways.

Me.YourFieldOnFormA = iif(CurrentProject.Allforms("FormB").IsLoaded, Forms!formB.YourFieldName, Forms!formC.YourOtherFieldName)
0
 

Author Closing Comment

by:allfredeneuman
ID: 38861812
Thanks. This will help a lot
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month4 days, 8 hours left to enroll

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