Solved

VB code syntax

Posted on 2013-02-06
4
302 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: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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

685 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