Solved

VB code syntax

Posted on 2013-02-06
4
301 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
  • 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:MrBullwinkle
MrBullwinkle 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Disable Outlook Security Warning Window Access 2016 5 52
Access 2010 change CurrentUser 5 35
Set WorkSheet  not Working 9 42
rECORD SET NOT UPDATEABLE 21 60
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

832 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