Solved

VB code syntax

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now