Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB code syntax

Posted on 2013-02-06
4
Medium Priority
?
305 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 1600 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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

670 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