473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Auto populating a field on form from another open form

sickenhoofer
I have a form, 'frmProviderMain' with a macro which opens another form, frmEnrollmentProcessing.The macro is located on a tab on 'frmProviderMain.' I would like one of the controls/fields on the secondary form, specifically [frmEnrollmentProcessing].[ProviderMainID], to fill in based on the selected provider on 'frmProviderMain'.

I attempted to set an event procedure which would set the value when the form loads as follows. However it does not work. As I am new to VBA, I am not sure if I have the language wrong, or if I am attempting it in the wrong way (and Access 2007 HELP is no help at all).

Here is the code I was using. . . . . .
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Me!frmProviderEnrollmentProcessing.Form!ProviderMainID.Value = Forms!frmProviderMain.Form!ProviderMainID
  3. End Sub
I appreciate any help, or suggestions for a better way to do this.
Jun 16 '09 #1
8 20645
I noticed that the posting appears to have a space in the middle of 'ProviderMainID.' However, there is no space in the code from which it was copied.
Jun 16 '09 #2
ChipR
1,287 Expert 1GB
Two ways to do this. I don't particularly like to reference controls on other forms, but you would use:
Expand|Select|Wrap|Line Numbers
  1. If CurrentProject.AllForms("frmProviderMain").IsLoaded Then
  2.   ProviderMainID = Forms!frmProviderMain!ProviderMainID
  3. End If
You would need the .Form if you were trying to reference a control on a subform. All that is explained in this chart (start at the top with "If you are on").

The other way is to pass the value as the OpenArgs argument of the DoCmd.OpenForm, like:
Expand|Select|Wrap|Line Numbers
  1. 'Somewhere in frmProviderMain code
  2.   DoCmd.OpenForm "frmEnrollmentProcessing", , , , , , ProviderMainID
  3.  
  4. 'In frmEnrollmentProcessing
  5. Private Sub Form_Open(Cancel As Integer)
  6.   If IsNull(OpenArgs) Then
  7.     MsgBox "No ID Number!"
  8.     DoCmd.Close acForm, "frmEnrollmentProcessing"
  9.   Else
  10.     ProviderMainID = OpenArgs
  11.   End If
  12. End Sub
If you need to pass more than one value, you can combine them in one string with a delimiter, then use Split to separate them in the other form.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "Sample", , , , , , value1 & "+" & value2
  2.  
  3. 'Sample Form_Open
  4.   Dim strArgs() as String
  5.   strArgs = Split(OpenArgs, "+")
  6.   value1 = strArgs(0)
  7.   value2 = strArgs(1)
Jun 16 '09 #3
Thanks for your response. I understand the first solution. However, I need to clarify something on the second one.

Am I correct in understanding that in the subprocedure you listed above (lines 4-12 in 2nd example), that the form (frmEnrollmentProcessing) would close if the providermainID field is null? Closing the form would not be the desired effect.

frmEnrollmentProcessing is a form into which data is entered, but I do not want it to be set to DataEntry = yes. I want the form to display all processing events (records) related to the provider on main form. A provider may not have begun enrollment processing yet . . .in which case it should open to a blank record. So, I wouldn't want it to open and then close if the control ProviderMainID on frmProviderEnrollmentProcessing is blank.

Sorry, if I am being dense. Did I say I was new to vba?:):)

In the event that I wasn't clear above, here is some clarification on set up:
Provider Main Info
*tblProviderMain (PK =ProviderMainID - Autonum)
*qryProviderMain (feeds frmProviderMain)
frmProviderMain (view only form)

Enrollment Processing
*tblEnrollmentProcessing (PK = EnrollmentProcessingID - Autonum) . . Also has ProviderMainID (joined globally)
*qryEnrollmentProcessing
*frmEnrollmentProcessing (opens via macro on a tab on frmProviderMain)

Thanks, for your help.
Jun 16 '09 #4
ChipR
1,287 Expert 1GB
Yes, in the example, the form would be closed. You can leave that out completely, or take other action as your application requires.

It sounds like you may want to simply filter the records in the form that you open using the WhereCondition argument, like:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "frmEnrollmentProcessing", , , "ProviderMainID = " & ProviderMainID
See OpenForm Method for more information.
Jun 16 '09 #5
I do want to filter as well, I just didn't list that, because I think I can get that part. My main goal was to eliminate the end user from typing the ProviderID in the field that joins it to the specific provider. In fact, that control is locked.

Although, now that you have me thinking . . . . once the filters are applied, will it automatically fill in the provider ID as they begin typing in the other fields? I know it does it for the Enrollmentprocessing Id (PK for that table).
Jun 16 '09 #6
ChipR
1,287 Expert 1GB
I see what you mean now, and I suppose a new record would not fill in the Provider ID automatically. Nothing better than using the OpenArgs comes to mind. In fact, you might have to save that ID in an invisible text box, and set the Provider ID equal to that when moving to a new record. Setting it just the one time in Form_Open will not be sufficient if more records will be added.
Jun 16 '09 #7
I appreciate all your feedback. I'm going to give the OpenArgs with the invisible text box a whirl tomorrow. Thanks, again!
Jun 16 '09 #8
NeoPa
32,556 Expert Mod 16PB
You've been well lead here (Filtering; OpenArgs; etc), but I suggest setting the .Default of the appropriate control as soon as the form is opened, rather than trying to set the value over and again.
Jun 17 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Irwinsp | last post by:
Hi All, I have a form with an auto number field displayed. The field looks great except when the user is entering a new record. The field then has the text "auto number" in it. Is there a...
5
by: Lyn | last post by:
Hi, I hope someone can help. I have a main form which mostly fills the Access window. In the bottom half of this form I have a tab control to display various types of data related to the main...
5
by: Geoff Portbury | last post by:
I'm a swimming club coach. I have a data base for recording times at various meets. I have a FORM for entering times called SWIM TIMES. When I enter the swimmers name ID, eg FOR01 for Doug Ford I...
3
by: Rolan | last post by:
I need assistance regarding code needed to prevent someone from opening a form if a table field name(s) has been changed. For example, there is existing code to check for certain data based on...
1
by: Steven C | last post by:
Hello: I am a Forxpro developer trying to come up to speed in C#. I'm trying to do in C# what I do effortlessly in Foxpro, and that is to call a grid refresh method in the parent form from the...
1
by: Jason Galvin | last post by:
I would like to disable the auto-populating feature (remembers form element text between post-backs) when creating a .NET form. I have succeeded in disabling auto-populate by creating my controls...
3
by: rdemyan via AccessMonster.com | last post by:
My application is split into a front end and back end. Each user has their own copy of the front end. There are a few forms I only want to be open for one user at a time. So I've implemented the...
11
by: ZaphodBBB | last post by:
Hi I have a table that has as its Primary Key the Auto-Increment Field: Equipment_Number. In M.S. Access is there any way to define a starting number for the field? OR another way in which...
5
by: David Wright | last post by:
Hello Everyone I would be grateful if someone could help me with the automatic increment of a field on my subform called ‘Test_SrNo’. I am Using Microsoft Office 2000. The auto entry of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.